pub fn ranges_difference<F>(
from: &[RawRange],
exclude: &[RawRange],
result_op: F,
) -> Result<(), OverlapErr>
Expand description
Removes a portion of ranges from the given ranges.
from
is a list of ranges to be operated on, and exclude
is a list of
ranges to be removed. exclude
should have been sorted by the start, and
have non-overlapping ranges. If not, an error will be returned.
The result is also a list of ranges with each range contained in from
but
not in exclude
. result_op
is a closure that will be called for each range
in the result.
ยงExample
let mut res = Vec::new();
// 0..10, 20..30 - 5..15, 15..25 = 0..5, 25..30
ranges_difference(&[(0, 10), (20, 10)], &[(5, 10), (15, 10)], |r| res.push(r)).unwrap();
assert_eq!(res, &[(0, 5), (25, 5)]);