Add drain_filter method to HashMap and HashSet by mbrubeck · Pull Request #76458 · rust-lang/rust (original) (raw)
Add HashMap::drain_filter
and HashSet::drain_filter
, implementing part of rust-lang/rfcs#2140. These new methods are unstable. The tracking issue is #59618.
The added iterators behave the same as BTreeMap::drain_filter
and BTreeSet::drain_filter
, except their iteration order is arbitrary. The unit tests are adapted from alloc::collections::btree
.
This branch rewrites HashSet
to be a wrapper around hashbrown::HashSet
rather than std::collections::HashMap
.
(Both are themselves wrappers around hashbrown::HashMap
, so the in-memory representation is the same either way.) This lets std
re-use more iterator code from hashbrown
. Without this change, we would need to duplicate much more code to implement HashSet::drain_filter
.
This branch also updates the hashbrown
crate to version 0.9.0. Aside from changes related to the DrainFilter
iterators, this version only changes features that are not used in libstd or rustc. And it updates indexmap
to version 1.6.0, whose only change is compatibility with hashbrown
0.9.0.