pub fn retain<F>(&mut self, mut f: F)
    where
        F: FnMut(&T) -> bool,
    {
        let len = self.len();
        let mut del = 0;
        {
            let v = self.to_slice_mut();

            for i in 0..len {
                if !f(&v[i]) {
                    del += 1;
                } else if del > 0 {
                    v.swap(i - del, i);
                }
            }
        }
        if del > 0 {
            self.truncate(len - del);
        }
    }
/// Retains only the elements specified by the predicate.
///
/// In other words, remove all elements `e` such that `f(&e)` returns `false`.
/// This method operates in place, visiting each element exactly once in the
/// original order, and preserves the order of the retained elements.
///
/// # Examples
///
/// ```
/// # use corundum::vec::Vec;
/// # use corundum::alloc::heap::*;
/// Heap::transaction(|j| {
///     let mut vec = Vec::from_slice(&[1, 2, 3, 4], j);
///     vec.retain(|&x| x % 2 == 0);
///     assert_eq!(vec, [2, 4]);
/// }).unwrap();
/// ```
///
/// The exact order may be useful for tracking external state, like an index.
///
/// ```
/// # use corundum::vec::Vec;
/// # use corundum::alloc::heap::*;
/// Heap::transaction(|j| {
///     let mut vec = Vec::from_slice(&[1, 2, 3, 4, 5], j);
///     let keep = [false, true, true, false, true];
///     let mut i = 0;
///     vec.retain(|_| (keep[i], i += 1).0);
///     assert_eq!(vec, [2, 3, 5]);
/// }).unwrap();
/// ```
Retains only the elements specified by the predicate.
Retains only the elements specified by the predicate .
pub fn retain<F>(&mut self, mut f: F)
    where
        F: FnMut(&T) -> bool,
    {
        let len = self.len();
        let mut del = 0;
        {
            let v = self.to_slice_mut();
            for i in 0..len {
                if !f(&v[i]) {
                    del += 1;
                } else if del > 0 {
                    v.swap(i - del, i);
                }
            }
        }
        if del > 0 {
            self.truncate(len - del);
        }
    }
pub fn retain < F > ( & mut self , mut f : F ) where F : FnMut ( & T ) -> bool , { let len = self . len ( ) ; let mut del = 0 ; { let v = self . to_slice_mut ( ) ; for i in 0 .. len { if ! f ( & v [ i ] ) { del += 1 ; } else if del > 0 { v . swap ( i - del , i ) ; } } } if del > 0 { self . truncate ( len - del ) ; } }
Retains only the elements specified by the predicate.
Retains only the elements specified by the predicate .
&mut self
f
F
examples
None
use corundum::vec::vec;
None
use corundum::alloc::heap::*;


The exact order may be useful for tracking external state, like an index.


The exact order may be useful for tracking external state like an index .
use corundum::vec::vec;
None
use corundum::alloc::heap::*;
None