Tracking issue for HashMap::extract_if and HashSet::extract_if · Issue #59618 · rust-lang/rust (original) (raw)
The feature gate for the issue is #![feature(hash_extract_if)]
(previously hash_drain_filter
)
Currently only Vec and LinkedList have a drain_filter method, while other collections such as HashMap and HashSet do not.
This means that currently, removing items from a collection, and getting ownership of those items is fairly...unidiomatic and cumbersome.
For references, see rust-lang/rfcs#2140
pub mod collections { pub mod hash_map { impl<K, V, S> HashMap<K, V, S> { pub fn extract_if(&mut self, pred: F) -> ExtractIf<'_, K, V, F> where F: FnMut(&K, &mut V) -> bool; }
pub struct ExtractIf<'a, K, V, F>
where
F: FnMut(&K, &mut V) -> bool;
impl<K, V, F> Iterator for ExtractIf<'_, K, V, F>
where
F: FnMut(&K, &mut V) -> bool;
impl<K, V, F> FusedIterator for ExtractIf<'_, K, V, F>
where
F: FnMut(&K, &mut V) -> bool;
impl<K, V, F> Debug for ExtractIf<'_, K, V, F>
where
F: FnMut(&K, &mut V) -> bool;
}
pub mod hash_set {
impl<T, S> HashSet<T, S> {
pub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, T, F>
where
F: FnMut(&T) -> bool;
}
pub struct ExtractIf<'a, K, F>
where
F: FnMut(&K) -> bool;
impl<K, F> Iterator for ExtractIf<'_, K, F>
where
F: FnMut(&K) -> bool;
impl<K, F> FusedIterator for ExtractIf<'_, K, F>
where
F: FnMut(&K) -> bool;
impl<K, F> Debug for ExtractIf<'_, K, F>
where
F: FnMut(&K) -> bool;
}
}
Implementation History
- Add drain_filter method to HashMap and HashSet #76458
- removed drain-on-drop behavior, renamed to extract_if