Struct vec_mut_scan::VecMutScan
source · 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>
impl<'a, T: 'a> VecMutScan<'a, T>
sourcepub fn new(vec: &mut Vec<T>) -> VecMutScan<'_, T>
pub fn new(vec: &mut Vec<T>) -> VecMutScan<'_, T>
Begin a scan over a vector with mutation and item removal.
sourcepub fn next<'s>(&'s mut self) -> Option<VecMutScanItem<'s, 'a, T>>
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
).
sourcepub fn slices(&self) -> (&[T], &[T])
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
.
sourcepub fn slices_mut(&mut self) -> (&mut [T], &mut [T])
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
.