Function memory_range::flatten_equivalent_ranges
source · pub fn flatten_equivalent_ranges<T: PartialEq>(
ranges: impl IntoIterator<Item = (MemoryRange, T)>,
) -> impl Iterator<Item = (MemoryRange, T)>
Expand description
Similar to flatten_ranges
, but also requires that ranges are equivalent
via the passed in closure. This can be useful when merging memory ranges
with associated tags.
Panics if the input ranges are not sorted by their start address, or if ranges overlap.
§Example
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum Color {
Red,
Blue,
}
let ranges = [
(MemoryRange::new(0x1000..0x2000), Color::Red),
(MemoryRange::new(0x2000..0x5000), Color::Red),
(MemoryRange::new(0x5000..0x6000), Color::Blue),
(MemoryRange::new(0x8000..0x9000), Color::Red),
];
let flattened = [
(MemoryRange::new(0x1000..0x5000), Color::Red),
(MemoryRange::new(0x5000..0x6000), Color::Blue),
(MemoryRange::new(0x8000..0x9000), Color::Red),
];
assert!(flatten_equivalent_ranges(ranges).eq(flattened));