Struct ChunksExactMut

#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct ChunksExactMut<'a, T: 'a> { pub(in ::slice::iter) v: *mut [T], pub(in ::slice::iter) rem: &'a mut [T], pub(in ::slice::iter) chunk_size: usize, pub(in ::slice::iter) _marker: PhantomData<&'a mut T> }

An iterator over a slice in (non-overlapping) mutable chunks (chunk_size elements at a time), starting at the beginning of the slice.

When the slice len is not evenly divided by the chunk size, the last up to chunk_size-1 elements will be omitted but can be retrieved from the into_remainder function from the iterator.

This struct is created by the chunks_exact_mut method on slices.

Example

let mut slice = ['l', 'o', 'r', 'e', 'm'];
let iter = slice.chunks_exact_mut(2);

Fields

v: *mut [T]

Safety

This slice pointer must point at a valid region of T with at least length v.len(). Normally, those requirements would mean that we could instead use a &mut [T] here, but we cannot because __iterator_get_unchecked needs to return &mut [T], which guarantees certain aliasing properties that we cannot uphold if we hold on to the full original &mut [T]. Wrapping a raw slice instead lets us hand out non-overlapping &mut [T] subslices of the slice we wrap.

rem: &'a mut [T]
chunk_size: usize
_marker: PhantomData<&'a mut T>

Implementations

impl<'a, T> ChunksExactMut<'a, T>

const fn new(slice: &'a mut [T], chunk_size: usize) -> Self
fn into_remainder(self) -> &'a mut [T]

Returns the remainder of the original slice that is not going to be returned by the iterator. The returned slice has at most chunk_size-1 elements.

Trait Implementations

impl<'a, T> DoubleEndedIterator for ChunksExactMut<'a, T>

fn next_back(&mut self) -> Option<&'a mut [T]>
fn nth_back(&mut self, n: usize) -> Option<Self::Item>

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

type Item = &'a mut [T];
fn next(&mut self) -> Option<&'a mut [T]>
fn size_hint(&self) -> (usize, Option<usize>)
fn count(self) -> usize
fn nth(&mut self, n: usize) -> Option<&'a mut [T]>
fn last(self) -> Option<Self::Item>
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item

impl<'a, T> TrustedRandomAccess for ChunksExactMut<'a, T>

impl<'a, T> TrustedRandomAccessNoCoerce for ChunksExactMut<'a, T>

const MAY_HAVE_SIDE_EFFECT: bool = false;

impl<'a, T: Debug + 'a> Debug for ChunksExactMut<'a, T>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

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

fn is_empty(&self) -> bool

impl<T> FusedIterator for ChunksExactMut<'_, T>

impl<T> Send for ChunksExactMut<'_, T> where T: Send,

impl<T> Sync for ChunksExactMut<'_, T> where T: Sync,

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

Auto Trait Implementations

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

impl<'a, T> Freeze for ChunksExactMut<'a, T> where *mut [T]: Freeze, &'a mut [T]: Freeze, PhantomData<&'a mut T>: Freeze,

impl<'a, T> RefUnwindSafe for ChunksExactMut<'a, T> where *mut [T]: RefUnwindSafe, &'a mut [T]: RefUnwindSafe, PhantomData<&'a mut T>: RefUnwindSafe,

impl<'a, T> Unpin for ChunksExactMut<'a, T> where *mut [T]: Unpin, &'a mut [T]: Unpin, PhantomData<&'a mut T>: Unpin,

impl<'a, T> UnsafeUnpin for ChunksExactMut<'a, T> where *mut [T]: UnsafeUnpin, &'a mut [T]: UnsafeUnpin, PhantomData<&'a mut T>: UnsafeUnpin,

Blanket Implementations

impl<I> IntoIterator for ChunksExactMut<'a, T> where I: Iterator,

type Item = <I as Iterator>::Item;
type IntoIter = I;
fn into_iter(self) -> I

impl<T> Any for ChunksExactMut<'a, T> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for ChunksExactMut<'a, T> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for ChunksExactMut<'a, T> where T: ?Sized,

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

impl<T> From<T> for ChunksExactMut<'a, T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for ChunksExactMut<'a, T> where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for ChunksExactMut<'a, T>

impl<T, U> Into<U> for ChunksExactMut<'a, T> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom<U> for ChunksExactMut<'a, T> where U: Into<T>,

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

impl<T, U> TryInto<U> for ChunksExactMut<'a, T> where U: TryFrom<T>,

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