[][src]Trait vec_drain_where::VecDrainWhereExt

pub trait VecDrainWhereExt<Item> {
    fn e_drain_where<F>(&mut self, predicate: F) -> VecDrainWhere<Item, F>
    where
        F: FnMut(&mut Item) -> bool
; }

Ext. trait adding e_drain_where to Vec

Required methods

Important traits for VecDrainWhere<'a, I, P>
fn e_drain_where<F>(&mut self, predicate: F) -> VecDrainWhere<Item, F> where
    F: FnMut(&mut Item) -> bool

Drains all elements from the vector where the predicate is true.

Note that dropping the iterator early will stop the process of draining. So for example if you add an combinator to the drain iterator which short circuits (e.g. any/all) this will stop draining once short circuiting is hit. So use it with care.

you can use fold e.g. any(pred) => `fold(false, |s| )

Leak Behavior

For safety reasons the length of the original vector is set to 0 while the drain iterator lives.

Panic/Drop Behavior

When the iterator is dropped due to an panic in the predicate the element it panicked on is leaked but all elements which have already been decided to not be drained and such which have not yet been decided about will still be in the vector safely. I.e. if the panic also causes the vector to drop they are normally dropped if not the vector still can be normally used.

Tip: non iterator short circuiting all/any

Instead of iter.any(pred) use iter.fold(false, |s,i| s|pred(i)).

Instead of iter.all(pred) use iter.fold(true, |s,i| s&pred(i)).

And if it is fine to not call pred once it's found/has show to not hold but it's still required to run the iterator to end in the normal case replace the | with || and the & with &&.

Loading content...

Implementations on Foreign Types

impl<Item> VecDrainWhereExt<Item> for Vec<Item>[src]

Loading content...

Implementors

Loading content...