Struct ExtractIf

#[must_use = "Iterators are lazy unless consumed"]
pub struct ExtractIf<'a, K, V, F, A: Allocator = Global> { /* private fields */ }

A draining iterator over entries of a HashMap which don't satisfy the predicate f(&k, &mut v) in arbitrary order. The iterator element type is (K, V).

This struct is created by the extract_if method on HashMap. See its documentation for more.

Examples

use hashbrown::HashMap;

let mut map: HashMap<i32, &str> = [(1, "a"), (2, "b"), (3, "c")].into();

let mut extract_if = map.extract_if(|k, _v| k % 2 != 0);
let mut vec = vec![extract_if.next(), extract_if.next()];

// The `ExtractIf` iterator produces items in arbitrary order, so the
// items must be sorted to test them against a sorted array.
vec.sort_unstable();
assert_eq!(vec, [Some((1, "a")),Some((3, "c"))]);

// It is fused iterator
assert_eq!(extract_if.next(), None);
assert_eq!(extract_if.next(), None);
drop(extract_if);

assert_eq!(map.len(), 1);

Trait Implementations

impl<K, V, F> FusedIterator for ExtractIf<'_, K, V, F> where F: FnMut(&K, &mut V) -> bool,

impl<K, V, F, A> Iterator for ExtractIf<'_, K, V, F, A> where F: FnMut(&K, &mut V) -> bool, A: Allocator,

type Item = (K, V);
fn next(&mut self) -> Option<Self::Item>
fn size_hint(&self) -> (usize, Option<usize>)

Auto Trait Implementations

impl<'a, K, V, F, A = Global> !UnwindSafe for ExtractIf<'a, K, V, F, A>

impl<'a, K, V, F, A> Freeze for ExtractIf<'a, K, V, F, A> where F: Freeze, RawExtractIf<'a, (K, V), A>: Freeze,

impl<'a, K, V, F, A> RefUnwindSafe for ExtractIf<'a, K, V, F, A> where F: RefUnwindSafe, RawExtractIf<'a, (K, V), A>: RefUnwindSafe,

impl<'a, K, V, F, A> Send for ExtractIf<'a, K, V, F, A> where F: Send, RawExtractIf<'a, (K, V), A>: Send,

impl<'a, K, V, F, A> Sync for ExtractIf<'a, K, V, F, A> where F: Sync, RawExtractIf<'a, (K, V), A>: Sync,

impl<'a, K, V, F, A> Unpin for ExtractIf<'a, K, V, F, A> where F: Unpin, RawExtractIf<'a, (K, V), A>: Unpin,

impl<'a, K, V, F, A> UnsafeUnpin for ExtractIf<'a, K, V, F, A> where F: UnsafeUnpin, RawExtractIf<'a, (K, V), A>: UnsafeUnpin,

Blanket Implementations

impl<I> IntoIterator for ExtractIf<'a, K, V, F, A> where I: Iterator,

type Item = <I as Iterator>::Item;
type IntoIter = I;
fn into_iter(self) -> I

impl<T> Any for ExtractIf<'a, K, V, F, A> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for ExtractIf<'a, K, V, F, A> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for ExtractIf<'a, K, V, F, A> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> From<T> for ExtractIf<'a, K, V, F, A>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into<U> for ExtractIf<'a, K, V, F, A> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for ExtractIf<'a, K, V, F, A> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for ExtractIf<'a, K, V, F, A> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>