Closed
Description
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<F>(&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
Metadata
Metadata
Assignees
Labels
Area: `std::collections`Category: An issue tracking the progress of sth. like the implementation of an RFCRelevant to the library API team, which will review and decide on the PR/issue.This issue / PR is in PFCP or FCP with a disposition to merge it.The final comment period is finished for this PR / Issue.Announce this issue on triage meeting