pub fn rangemap_mutate_range<K, V, StepFnsT, E>(
map: &mut RangeInclusiveMap<K, V, StepFnsT>,
range0: &RangeInclusive<K>,
update: impl FnMut(&mut Option<V>, &RangeInclusive<K>) -> Result<(), E>,
) -> Result<(), E>Expand description
Read-modify-write values for a contiguous range of keys, in a range map
Since the map might contain different values for various parts of the specified range,
multiple possible old values might need to be handled.
rangemap_mutate_range is suitable if different old values can be handled independently,
or sequentially.
Calls update for every range currently in the map overlapping with range0,
and for every gap overlapping with range.
If the mutated value is equal (PartialEq), no actual update is made.
If update throws Err, any mutations to its first argument will be stored in the map,
but no further calls to update will be made (so only part of the range
might be updated).
update should probably not use the provided &RangeInclusive argument as an input
to calculating how to update the &mut V. Doing so would make the results depend
on the details of range fragmentation in the rangemap,
which would be inconsistent with the usual use of a rangemap as an optimisation
of an abstract data structure which stores a separate value for each key.
Note that update doesn’t get a mutable reference into the map.
so if it mutates its argument and then panics, the update might not be applied.