ExtractIf

Struct ExtractIf 

Source
pub struct ExtractIf<'a, K, V, F, A = Global>
where A: Allocator, F: FnMut(&K, &mut V) -> bool,
{ /* private fields */ }
Expand description

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 rune::alloc::HashMap;

let mut map: HashMap<i32, &str> = [(1, "a"), (2, "b"), (3, "c")].try_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);

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<I> IntoIterator for I
where I: Iterator,

Source§

type Item = <I as Iterator>::Item

The type of the elements being iterated over.
Source§

type IntoIter = I

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> I

Creates an iterator from a value. Read more
Source§

impl<I> IteratorExt for I
where I: Iterator,

Source§

fn try_collect<B>(self) -> Result<B, Error>
where Self: Sized, B: TryFromIteratorIn<Self::Item, Global>,

Transforms an iterator into a collection using fallible allocations.
Source§

fn try_collect_in<B, A>(self, alloc: A) -> Result<B, Error>
where Self: Sized, B: TryFromIteratorIn<Self::Item, A>, A: Allocator,

Transforms an iterator into a collection using fallible allocations.
Source§

fn try_join<J, S>(self, sep: S) -> Result<J, Error>
where Self: Sized, J: TryJoin<S, Self::Item, Global>,

Try to join the given value. Read more
Source§

fn try_join_in<J, S, A>(self, sep: S, alloc: A) -> Result<J, Error>
where Self: Sized, J: TryJoin<S, Self::Item, A>, A: Allocator,

Try to join the given value.
Source§

fn try_cloned<'a, T>(self) -> TryCloned<Self>
where Self: Sized + Iterator<Item = &'a T>, T: 'a + TryClone,

Creates an iterator which try_clones all of its elements. Read more
Source§

impl<I> IteratorRandom for I
where I: Iterator,

Source§

fn choose<R>(self, rng: &mut R) -> Option<Self::Item>
where R: Rng + ?Sized,

Uniformly sample one element Read more
Source§

fn choose_stable<R>(self, rng: &mut R) -> Option<Self::Item>
where R: Rng + ?Sized,

Uniformly sample one element (stable) Read more
Source§

fn choose_multiple_fill<R>(self, rng: &mut R, buf: &mut [Self::Item]) -> usize
where R: Rng + ?Sized,

Uniformly sample amount distinct elements into a buffer Read more
Source§

fn choose_multiple<R>(self, rng: &mut R, amount: usize) -> Vec<Self::Item>
where R: Rng + ?Sized,

Uniformly sample amount distinct elements into a Vec Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,