[−][src]Struct scanmut::Remover
An object that can remove multiple elements from a Vec
in a single scan through the Vec
.
The indices of the removed elements must be monotonically increasing (i.e. the next index most be more than the previous index).
The elements below the last removed index are the filtered elements, while the elements above
the last removed index are the unfiltered elements. Initially all elements are unfiltered. As
the Remover
progresses over the Vec
, these elements are either removed or moved to the
filtered elements.
Leaking the remover (through std::mem::forget
or similar) will leave the filtered elements in
the Vec
and leak the unfiltered elements.
Example
use scanmut::Remover; let mut items = vec![1, 2, 3]; let mut remover = Remover::new(&mut items); assert_eq!(remover.remove(0), 1); assert_eq!(remover.remove(2), 3); drop(remover); assert_eq!(items, [2]);
Methods
impl<'a, T> Remover<'a, T>
[src]
pub fn new(vec: &'a mut Vec<T>) -> Remover<'a, T>
[src]
Create a new new Remover
for removing elements from a Vec
.
pub fn min_index(&self) -> usize
[src]
The minimum index allowed for the next remove.
pub fn len(&self) -> usize
[src]
The length of the original Vec
.
pub fn filtered(&self) -> &[T]
[src]
Get a slice of the filtered elements.
pub fn filtered_mut(&mut self) -> &mut [T]
[src]
Get a mutable slice of the filtered elements.
pub fn unfiltered(&self) -> &[T]
[src]
Get a slice of the unfiltered elements.
pub fn unfiltered_mut(&mut self) -> &mut [T]
[src]
Get a mutable slice of the unfiltered elements.
pub fn advance_to(&mut self, index: usize)
[src]
Advances the index of this Remover
without removing an item.
pub fn remove(&mut self, index: usize) -> T
[src]
Removes an element from the vec at the specified index.
Panics
Panics if
- The index is less than or equal to the last index.
- The index is larger than the size of the vec.
Trait Implementations
Auto Trait Implementations
impl<'a, T> Unpin for Remover<'a, T>
impl<'a, T> Send for Remover<'a, T> where
T: Send,
T: Send,
impl<'a, T> Sync for Remover<'a, T> where
T: Sync,
T: Sync,
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,