Going back to the original question, and related topics, I see these related methods:
-
drain(range)
, equivalent toVec::drain(range)
if you consider aVec<T>
to be aBTreeMap<usize, T>
with consecutive keys. -
drain()
, equivalent toHashMap::drain()
, a shortcut tomem::take(&mut self).into_iter()
. This is equivalent toVec::drain(..)
but not quite equivalent toBTreeMap::drain(..)
. -
split_off(range)
: adrain(range)
that returns a new map instead of merely iterating it. This is not just a generalization ofdrain(range)
, because a map has more constraints to comply with than an iterator. It could be accomplished by aDrain::into_map
method, but that's also not ideal: the iteratorDrain
descends to the first leaf node to start iteration, andinto_map
would need to back up to the root. The existingsplit_off(key)
is equivalent tosplit_off(key..)
. A desired variantis split_off((Excluded(key), Unbounded))
.
The problem now is getting the names right. Both of the names above are overloaded thus impossible. split_off(key)
is stable I don't see an alternative to split_off_range(range)
. Should it be drain_range(range)
, which also seems more fair against drain_filter
? And/or should we forget about a separate drain()
?