pub fn retain<F>(&mut self, mut func: F)
	where F: FnMut(usize, &bool) -> bool {
		let mut len = self.len();
		let mut hole_ptr = self.as_mut_bitptr();
		let mut reader = self.as_bitptr_range().enumerate();

		//  Advance until the *first* hole is created. This avoids writing into
		//  the bit-slice when no change takes place.
		for (idx, bitptr) in reader.by_ref() {
			let bit = unsafe { bitptr.read() };
			if func(idx, &bit) {
				hole_ptr = unsafe { hole_ptr.add(1) };
			}
			else {
				len -= 1;
				break;
			}
		}
		//  Now that a hole exists, switch to a loop that always writes into the
		//  hole pointer.
		for (idx, bitptr) in reader {
			let bit = unsafe { bitptr.read() };
			if func(idx, &bit) {
				hole_ptr = unsafe {
					hole_ptr.write(bit);
					hole_ptr.add(1)
				};
			}
			else {
				len -= 1;
			}
		}
		//  Discard the bits that did not survive the predicate.
		unsafe {
			self.set_len_unchecked(len);
		}
	}
/// Retains only the bits that the predicate allows.
///
/// Bits are deleted from the vector when the predicate function returns
/// false. This function is linear in `self.len()`.
///
/// ## Original
///
/// [`Vec::retain`](alloc::vec::Vec::retain)
///
/// ## API Differences
///
/// The predicate receives both the index of the bit as well as its value,
/// in order to allow the predicate to have more than one bit of
/// keep/discard information.
///
/// ## Examples
///
/// ```rust
/// use bitvec::prelude::*;
///
/// let mut bv = bitvec![0, 1, 0, 0, 1];
/// bv.retain(|idx, _| idx % 2 == 0);
/// assert_eq!(bv, bits![0,    0,    1]);
/// ```
Retains only the bits that the predicate allows.
Bits are deleted from the vector when the predicate function returns
false. This function is linear in `self.len()`.
Retains only the bits that the predicate allows . Bits are deleted from the vector when the predicate function returns false . This function is linear in ` self . len () ` .
pub fn retain<F>(&mut self, mut func: F)
	where F: FnMut(usize, &bool) -> bool {
		let mut len = self.len();
		let mut hole_ptr = self.as_mut_bitptr();
		let mut reader = self.as_bitptr_range().enumerate();
		//  Advance until the *first* hole is created. This avoids writing into
		//  the bit-slice when no change takes place.
		for (idx, bitptr) in reader.by_ref() {
			let bit = unsafe { bitptr.read() };
			if func(idx, &bit) {
				hole_ptr = unsafe { hole_ptr.add(1) };
			}
			else {
				len -= 1;
				break;
			}
		}
		//  Now that a hole exists, switch to a loop that always writes into the
		//  hole pointer.
		for (idx, bitptr) in reader {
			let bit = unsafe { bitptr.read() };
			if func(idx, &bit) {
				hole_ptr = unsafe {
					hole_ptr.write(bit);
					hole_ptr.add(1)
				};
			}
			else {
				len -= 1;
			}
		}
		//  Discard the bits that did not survive the predicate.
		unsafe {
			self.set_len_unchecked(len);
		}
	}
pub fn retain < F > ( & mut self , mut func : F ) where F : FnMut ( usize , & bool ) -> bool { let mut len = self . len ( ) ; let mut hole_ptr = self . as_mut_bitptr ( ) ; let mut reader = self . as_bitptr_range ( ) . enumerate ( ) ; //  Advance until the *first* hole is created. This avoids writing into //  the bit-slice when no change takes place. for ( idx , bitptr ) in reader . by_ref ( ) { let bit = unsafe { bitptr . read ( ) } ; if func ( idx , & bit ) { hole_ptr = unsafe { hole_ptr . add ( 1 ) } ; } else { len -= 1 ; break ; } } //  Now that a hole exists, switch to a loop that always writes into the //  hole pointer. for ( idx , bitptr ) in reader { let bit = unsafe { bitptr . read ( ) } ; if func ( idx , & bit ) { hole_ptr = unsafe { hole_ptr . write ( bit ) ; hole_ptr . add ( 1 ) } ; } else { len -= 1 ; } } //  Discard the bits that did not survive the predicate. unsafe { self . set_len_unchecked ( len ) ; } }
Retains only the bits that the predicate allows.
Retains only the bits that the predicate allows .
&mut self
func
F
&mut self
func
F
original
None
api differences
The predicate receives both the index of the bit as well as its value,
in order to allow the predicate to have more than one bit of
keep/discard information.
The predicate receives both the index of the bit as well as its value in order to allow the predicate to have more than one bit of keep / discard information .
examples
```rust
use bitvec::prelude::*.


` ` ` rust use bitvec :: prelude :: * .