Trait retain_mut::RetainMut
source · pub trait RetainMut<T> {
fn retain_mut<F>(&mut self, f: F)
where
F: FnMut(&mut T) -> bool;
}
Expand description
Trait that provides retain_mut
method.
Required Methods
sourcefn retain_mut<F>(&mut self, f: F)where
F: FnMut(&mut T) -> bool,
fn retain_mut<F>(&mut self, f: F)where
F: FnMut(&mut T) -> bool,
Retains only the elements specified by the predicate with a mutable borrow.
In other words, remove all elements e
such that f(&mut e)
returns false
.
This method operates in place and preserves the order of the retained
elements.
Examples
use retain_mut::RetainMut;
let mut vec = vec![1, 2, 3, 4];
vec.retain_mut(|x| { *x *= 3; *x % 2 == 0 });
assert_eq!(vec, [6, 12]);