Struct ChunksExact

struct ChunksExact<'a, T: 'a> { ... }

An iterator over a slice in (non-overlapping) 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 remainder function from the iterator.

This struct is created by the chunks_exact method on slices.

Example

let slice = ['l', 'o', 'r', 'e', 'm'];
let mut iter = slice.chunks_exact(2);
assert_eq!(iter.next(), Some(&['l', 'o'][..]));
assert_eq!(iter.next(), Some(&['r', 'e'][..]));
assert_eq!(iter.next(), None);

Implementations

impl<'a, T> ChunksExact<'a, T>

fn remainder(self: &Self) -> &'a [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.

Example

let slice = ['l', 'o', 'r', 'e', 'm'];
let mut iter = slice.chunks_exact(2);
assert_eq!(iter.remainder(), &['m'][..]);
assert_eq!(iter.next(), Some(&['l', 'o'][..]));
assert_eq!(iter.remainder(), &['m'][..]);
assert_eq!(iter.next(), Some(&['r', 'e'][..]));
assert_eq!(iter.remainder(), &['m'][..]);
assert_eq!(iter.next(), None);
assert_eq!(iter.remainder(), &['m'][..]);

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

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

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

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

fn next(self: &mut Self) -> Option<&'a [T]>
fn size_hint(self: &Self) -> (usize, Option<usize>)
fn count(self: Self) -> usize
fn nth(self: &mut Self, n: usize) -> Option<<Self as >::Item>
fn last(self: Self) -> Option<<Self as >::Item>

impl<'a, T> RefUnwindSafe for ChunksExact<'a, T>

impl<'a, T> Send for ChunksExact<'a, T>

impl<'a, T> Sync for ChunksExact<'a, T>

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

impl<'a, T> UnsafeUnpin for ChunksExact<'a, T>

impl<'a, T> UnwindSafe for ChunksExact<'a, T>

impl<'a, T: $crate::fmt::Debug + 'a> Debug for ChunksExact<'a, T>

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

impl<I> IntoIterator for ChunksExact<'a, T>

fn into_iter(self: Self) -> I

impl<T> Any for ChunksExact<'a, T>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for ChunksExact<'a, T>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for ChunksExact<'a, T>

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

impl<T> Clone for ChunksExact<'_, T>

fn clone(self: &Self) -> Self

impl<T> CloneToUninit for ChunksExact<'a, T>

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

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

fn is_empty(self: &Self) -> bool

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

fn from(t: T) -> T

Returns the argument unchanged.

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

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

impl<T, U> Into for ChunksExact<'a, T>

fn into(self: 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 for ChunksExact<'a, T>

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

impl<T, U> TryInto for ChunksExact<'a, T>

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