Function memory_range::walk_ranges
source · pub fn walk_ranges<T: Clone, U: Clone>(
left: impl IntoIterator<Item = (MemoryRange, T)>,
right: impl IntoIterator<Item = (MemoryRange, U)>,
) -> impl Iterator<Item = (MemoryRange, RangeWalkResult<T, U>)>
Expand description
Returns an iterator that computes the overlapping state of the ranges in
left
and right
.
The iterator yields a tuple of a MemoryRange
and a RangeWalkResult
enum that indicates whether each subrange is only in left
, only in
right
, in both, or in neither.
Panics if left
or right
are not sorted.
§Examples
let left = [(MemoryRange::new(0x100000..0x400000), "first"), (MemoryRange::new(0x800000..0xc00000), "second")];
let right = [(MemoryRange::new(0x200000..0x900000), 1000), (MemoryRange::new(0x900000..0xa00000), 2000)];
let v: Vec<_> = walk_ranges(left, right).collect();
let expected = [
(MemoryRange::new(0..0x100000), RangeWalkResult::Neither),
(MemoryRange::new(0x100000..0x200000), RangeWalkResult::Left("first")),
(MemoryRange::new(0x200000..0x400000), RangeWalkResult::Both("first", 1000)),
(MemoryRange::new(0x400000..0x800000), RangeWalkResult::Right(1000)),
(MemoryRange::new(0x800000..0x900000), RangeWalkResult::Both("second", 1000)),
(MemoryRange::new(0x900000..0xa00000), RangeWalkResult::Both("second", 2000)),
(MemoryRange::new(0xa00000..0xc00000), RangeWalkResult::Left("second")),
(MemoryRange::new(0xc00000..MemoryRange::MAX_ADDRESS), RangeWalkResult::Neither),
];
assert_eq!(v.as_slice(), expected.as_slice());