pub struct VecMutScan<'a, T: 'a> { /* private fields */ }
Expand description

Forward scan over a vector with mutation and item removal.

Provides an iterator like interface over a vector which allows mutation and removal of items.

If you need to also add new elements, see VecGrowScan.

Items are kept in order and every item is moved at most once, even when items are removed. Dropping the VecMutScan mid-iteration keeps remaining items in the vector.

This does not implement the iterator trait, as the returned items borrow from this (i.e. this is a streaming iterator).

The next method returns VecMutScanItem values, which auto dereference to the vector’s item type but also provide a remove and replace method.

Implementations§

source§

impl<'a, T: 'a> VecMutScan<'a, T>

source

pub fn new(vec: &mut Vec<T>) -> VecMutScan<'_, T>

Begin a scan over a vector with mutation and item removal.

source

pub fn next<'s>(&'s mut self) -> Option<VecMutScanItem<'s, 'a, T>>

Advance to the next item of the vector.

This returns a reference wrapper that enables item removal (see VecMutScanItem).

source

pub fn slices(&self) -> (&[T], &[T])

Access the whole vector.

This provides access to the whole vector at any point during the scan. In general while scanning, the vector content is not contiguous, thus it is returned as two slices, a prefix and a suffix. The prefix contains all elements already visited while the suffix contains the remaining elements starting with the element that will be returned by the following next call.

This method is also present on the VecMutScanItem reference wrapper returned by next, allowing access while that wrapper borrows this VecMutScan.

source

pub fn slices_mut(&mut self) -> (&mut [T], &mut [T])

Access and mutate the whole vector.

This provides mutable access to the whole vector at any point during the scan. In general while scanning, the vector content is not contiguous, thus it is returned as two slices, a prefix and a suffix. The prefix contains all elements already visited while the suffix contains the remaining elements starting with the element that will be returned by the following next call.

This method is also present on the VecMutScanItem reference wrapper returned by next, allowing access while that wrapper borrows this VecMutScan.

Trait Implementations§

source§

impl<'a, T: 'a> Drop for VecMutScan<'a, T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, T> RefUnwindSafe for VecMutScan<'a, T>where T: RefUnwindSafe,

§

impl<'a, T> !Send for VecMutScan<'a, T>

§

impl<'a, T> !Sync for VecMutScan<'a, T>

§

impl<'a, T> Unpin for VecMutScan<'a, T>

§

impl<'a, T> !UnwindSafe for VecMutScan<'a, T>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.