Crate retain_mut[−][src]
This crate provides trait RetainMut
which
provides retain_mut
method for Vec
and VecDeque
.
retain_mut
is basically the same as retain
except that
it gives mutable reference of items to the predicate function.
Since there is no reason retain
couldn’t have been designed this way,
this crate basically just copies the code from std with minor (1-line) change
to hand out mutable reference.
The code these impls are based on can be found in code comments of this crate.
Examples
Vec
let mut vec = vec![1, 2, 3, 4]; vec.retain_mut(|x| { *x *= 3; *x % 2 == 0 }); assert_eq!(vec, [6, 12]);
VecDeque
let mut deque = VecDeque::from(vec![1, 2, 3, 4]); deque.retain_mut(|x| { *x *= 3; *x % 2 == 0 }); assert_eq!(deque, [6, 12]);
Traits
RetainMut | Trait that provides |