Struct IterMut
struct IterMut<'a, T: 'a> { ... }
Mutable slice iterator.
This struct is created by the iter_mut method on slices.
Examples
Basic usage:
// First, we need a slice to call the `iter_mut` method on:
let slice = &mut ;
// Then we call `iter_mut` on the slice to get the `IterMut` iterator,
// iterate over it and increment each element value:
for element in slice.iter_mut
// We now have "[2, 3, 4]":
println!;
Implementations
impl<'a, T> IterMut<'a, T>
fn into_slice(self: Self) -> &'a mut [T]Views the underlying data as a subslice of the original data.
To avoid creating
&mutreferences that alias, this is forced to consume the iterator.Examples
Basic usage:
// First, we need a slice to call the `iter_mut` method on: let mut slice = &mut ; // Then we call `iter_mut` on the slice to get the `IterMut` struct: let mut iter = slice.iter_mut; // Now, we call the `next` method to remove the first element of the iterator, // unwrap and dereference what we get from `next` and increase its value by 1: *iter.next.unwrap += 1; // Here the iterator does not contain the first element of the slice any more, // so `into_slice` only returns the last two elements of the slice, // and so this prints "[2, 3]": println!; // The underlying slice still contains three elements, but its first element // was increased by 1, so this prints "[2, 2, 3]": println!;fn as_slice(self: &Self) -> &[T]Views the underlying data as a subslice of the original data.
Examples
Basic usage:
// First, we need a slice to call the `iter_mut` method on: let slice = &mut ; // Then we call `iter_mut` on the slice to get the `IterMut` iterator: let mut iter = slice.iter_mut; // Here `as_slice` still returns the whole slice, so this prints "[1, 2, 3]": println!; // Now, we call the `next` method to remove the first element from the iterator // and increment its value: *iter.next.unwrap += 1; // Here the iterator does not contain the first element of the slice any more, // so `as_slice` only returns the last two elements of the slice, // and so this prints "[2, 3]": println!; // The underlying slice still contains three elements, but its first element // was increased by 1, so this prints "[2, 2, 3]": println!;fn as_mut_slice(self: &mut Self) -> &mut [T]Views the underlying data as a mutable subslice of the original data.
Examples
Basic usage:
let mut slice: &mut = &mut ; // First, we get the iterator: let mut iter = slice.iter_mut; // Then, we get a mutable slice from it: let mut_slice = iter.as_mut_slice; // So if we check what the `as_mut_slice` method returned, we have "[1, 2, 3]": assert_eq!; // We can use it to mutate the slice: mut_slice = 4; mut_slice = 5; // Next, we can move to the second element of the slice, checking that // it yields the value we just wrote: assert_eq!; // Now `as_mut_slice` returns "[2, 5]": assert_eq!;
impl<'a, T> DoubleEndedIterator for IterMut<'a, T>
fn next_back(self: &mut Self) -> Option<&'a mut T>fn nth_back(self: &mut Self, n: usize) -> Option<&'a mut T>fn advance_back_by(self: &mut Self, n: usize) -> Result<(), NonZero<usize>>
impl<'a, T> Freeze for IterMut<'a, T>
impl<'a, T> Iterator for IterMut<'a, T>
fn next(self: &mut Self) -> Option<&'a mut T>fn next_chunk<N: usize>(self: &mut Self) -> Result<[&'a mut T; N], IntoIter<&'a mut T, N>>fn size_hint(self: &Self) -> (usize, Option<usize>)fn count(self: Self) -> usizefn nth(self: &mut Self, n: usize) -> Option<&'a mut T>fn advance_by(self: &mut Self, n: usize) -> Result<(), NonZero<usize>>fn last(self: Self) -> Option<&'a mut T>fn fold<B, F>(self: Self, init: B, f: F) -> B where F: FnMut(B, <Self as >::Item) -> Bfn for_each<F>(self: Self, f: F) where Self: Sized, F: FnMut(<Self as >::Item)fn all<F>(self: &mut Self, f: F) -> bool where Self: Sized, F: FnMut(<Self as >::Item) -> boolfn any<F>(self: &mut Self, f: F) -> bool where Self: Sized, F: FnMut(<Self as >::Item) -> boolfn find<P>(self: &mut Self, predicate: P) -> Option<<Self as >::Item> where Self: Sized, P: FnMut(&<Self as >::Item) -> boolfn find_map<B, F>(self: &mut Self, f: F) -> Option<B> where Self: Sized, F: FnMut(<Self as >::Item) -> Option<B>fn position<P>(self: &mut Self, predicate: P) -> Option<usize> where Self: Sized, P: FnMut(<Self as >::Item) -> boolfn rposition<P>(self: &mut Self, predicate: P) -> Option<usize> where P: FnMut(<Self as >::Item) -> bool, Self: Sized + ExactSizeIterator + DoubleEndedIterator
impl<'a, T> RefUnwindSafe for IterMut<'a, T>
impl<'a, T> Unpin for IterMut<'a, T>
impl<'a, T> UnsafeUnpin for IterMut<'a, T>
impl<'a, T> UnwindSafe for IterMut<'a, T>
impl<I> IntoIterator for IterMut<'a, T>
fn into_iter(self: Self) -> I
impl<T> Any for IterMut<'a, T>
fn type_id(self: &Self) -> TypeId
impl<T> AsRef for IterMut<'_, T>
fn as_ref(self: &Self) -> &[T]
impl<T> Borrow for IterMut<'a, T>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for IterMut<'a, T>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> Default for IterMut<'_, T>
fn default() -> SelfCreates an empty slice iterator.
# use IterMut; let iter: IterMut < '_, u8 > = Defaultdefault; assert_eq!;
impl<T> ExactSizeIterator for IterMut<'_, T>
fn len(self: &Self) -> usizefn is_empty(self: &Self) -> bool
impl<T> From for IterMut<'a, T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> FusedIterator for IterMut<'_, T>
impl<T> TrustedLen for IterMut<'_, T>
impl<T, U> Into for IterMut<'a, T>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for IterMut<'a, T>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for IterMut<'a, T>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>
impl<T: Send> Send for IterMut<'_, T>
impl<T: Sync> Sync for IterMut<'_, T>
impl<T: fmt::Debug> Debug for IterMut<'_, T>
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result