IterMut

Struct IterMut 

1.6.0 · Source
pub struct IterMut<'a, T: 'a> { /* private fields */ }
Expand description

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 [1, 2, 3];

// 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() {
    *element += 1;
}

// We now have "[2, 3, 4]":
println!("{slice:?}");

Implementations§

Source§

impl<'a, T> IterMut<'a, T>

Source

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

🔬This is a nightly-only experimental API. (slice_iter_mut_as_mut_slice #93079)

Views the underlying data as a mutable subslice of the original data.

§Examples

Basic usage:

#![feature(slice_iter_mut_as_mut_slice)]

let mut slice: &mut [usize] = &mut [1, 2, 3];

// 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!(mut_slice, &mut [1, 2, 3]);

// We can use it to mutate the slice:
mut_slice[0] = 4;
mut_slice[2] = 5;

// Next, we can move to the second element of the slice, checking that
// it yields the value we just wrote:
assert_eq!(iter.next(), Some(&mut 4));
// Now `as_mut_slice` returns "[2, 5]":
assert_eq!(iter.as_mut_slice(), &mut [2, 5]);

Trait Implementations§

1.0.0 · Source§

impl<T> ExactSizeIterator for IterMut<'_, T>

Source§

fn len(&self) -> usize

Ferrocene addition: Gate default implementation
Source§

fn is_empty(&self) -> bool

🔬This is a nightly-only experimental API. (exact_size_is_empty #35428)
Returns true if the iterator is empty. Read more
1.0.0 · Source§

impl<'a, T> Iterator for IterMut<'a, T>

Source§

type Item = &'a mut T

The type of the elements being iterated over.
Source§

fn next(&mut self) -> Option<&'a mut T>

Advances the iterator and returns the next value. Read more
Source§

fn nth(&mut self, n: usize) -> Option<&'a mut T>

Returns the nth element of the iterator. Read more
Source§

fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>>

🔬This is a nightly-only experimental API. (iter_advance_by #77404)
Advances the iterator by n elements. Read more
Source§

fn fold<B, F>(self, init: B, f: F) -> B
where F: FnMut(B, Self::Item) -> B,

Folds every element into an accumulator by applying an operation, returning the final result. Read more
Source§

fn for_each<F>(self, f: F)
where Self: Sized, F: FnMut(Self::Item),

Calls a closure on each element of an iterator. Read more
Source§

fn all<F>(&mut self, f: F) -> bool
where Self: Sized, F: FnMut(Self::Item) -> bool,

Tests if every element of the iterator matches a predicate. Read more
Source§

fn any<F>(&mut self, f: F) -> bool
where Self: Sized, F: FnMut(Self::Item) -> bool,

Tests if any element of the iterator matches a predicate. Read more
Source§

fn find<P>(&mut self, predicate: P) -> Option<Self::Item>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Searches for an element of an iterator that satisfies a predicate. Read more
Source§

fn position<P>(&mut self, predicate: P) -> Option<usize>
where Self: Sized, P: FnMut(Self::Item) -> bool,

Searches for an element in an iterator, returning its index. Read more
1.0.0 · Source§

fn size_hint(&self) -> (usize, Option<usize>)

Returns the bounds on the remaining length of the iterator. Read more
1.28.0 · Source§

fn step_by(self, step: usize) -> StepBy<Self>
where Self: Sized,

Creates an iterator starting at the same point, but stepping by the given amount at each iteration. Read more
1.0.0 · Source§

fn zip<U>(self, other: U) -> Zip<Self, U::IntoIter>
where Self: Sized, U: IntoIterator,

‘Zips up’ two iterators into a single iterator of pairs. Read more
1.0.0 · Source§

fn map<B, F>(self, f: F) -> Map<Self, F>
where Self: Sized, F: FnMut(Self::Item) -> B,

Takes a closure and creates an iterator which calls that closure on each element. Read more
1.0.0 · Source§

fn filter<P>(self, predicate: P) -> Filter<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Creates an iterator which uses a closure to determine if an element should be yielded. Read more
1.0.0 · Source§

fn enumerate(self) -> Enumerate<Self>
where Self: Sized,

Creates an iterator which gives the current iteration count as well as the next value. Read more
1.0.0 · Source§

fn skip(self, n: usize) -> Skip<Self>
where Self: Sized,

Creates an iterator that skips the first n elements. Read more
1.0.0 · Source§

fn take(self, n: usize) -> Take<Self>
where Self: Sized,

Creates an iterator that yields the first n elements, or fewer if the underlying iterator ends sooner. Read more
1.0.0 · Source§

fn collect<B: FromIterator<Self::Item>>(self) -> B
where Self: Sized,

Transforms an iterator into a collection. Read more
1.27.0 · Source§

fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R
where Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Output = B>,

An iterator method that applies a function as long as it returns successfully, producing a single, final value. Read more
1.51.0 · Source§

fn reduce<F>(self, f: F) -> Option<Self::Item>
where Self: Sized, F: FnMut(Self::Item, Self::Item) -> Self::Item,

Reduces the elements to a single one, by repeatedly applying a reducing operation. Read more
1.15.0 · Source§

fn max_by<F>(self, compare: F) -> Option<Self::Item>
where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Ordering,

Returns the element that gives the maximum value with respect to the specified comparison function. Read more
1.0.0 · Source§

fn cloned<'a, T>(self) -> Cloned<Self>
where T: Clone + 'a, Self: Sized + Iterator<Item = &'a T>,

Creates an iterator which clones all of its elements. Read more
1.11.0 · Source§

fn sum<S>(self) -> S
where Self: Sized, S: Sum<Self::Item>,

Sums the elements of an iterator. Read more
1.0.0 · Source§

impl<T: Send> Send for IterMut<'_, T>

1.0.0 · Source§

impl<T: Sync> Sync for IterMut<'_, T>

Source§

impl<T> TrustedLen for IterMut<'_, T>

Auto Trait Implementations§

§

impl<'a, T> Freeze for IterMut<'a, T>

§

impl<'a, T> Unpin for IterMut<'a, T>
where T: Unpin,

Blanket Implementations§

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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<I> IntoIterator for I
where I: Iterator,

Source§

type Item = <I as Iterator>::Item

The type of the elements being iterated over.
Source§

type IntoIter = I

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> I

Creates an iterator from a value. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.