Struct ArrayChunks

#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct ArrayChunks<I: Iterator, const N: usize> { pub(in ::iter::adapters::array_chunks) iter: I, pub(in ::iter::adapters::array_chunks) remainder: Option<IntoIter<I::Item, N>> }

An iterator over N elements of the iterator at a time.

The chunks do not overlap. If N does not divide the length of the iterator, then the last up to N-1 elements will be omitted.

This struct is created by the [array_chunks][Iterator::array_chunks] method on Iterator. See its documentation for more.

Fields

iter: I
remainder: Option<IntoIter<I::Item, N>>

Implementations

impl<I, const N: usize> ArrayChunks<I, N> where I: DoubleEndedIterator + ExactSizeIterator,

fn next_back_remainder(&mut self)

Updates self.remainder such that self.iter.len is divisible by N.

impl<I, const N: usize> ArrayChunks<I, N> where I: Iterator,

const fn new(iter: I) -> Self
fn into_remainder(self) -> IntoIter<I::Item, N>

Returns an iterator over the remaining elements of the original iterator that are not going to be returned by this iterator. The returned iterator will yield at most N-1 elements.

Example

# // Also serves as a regression test for https://github.com/rust-lang/rust/issues/123333
# #![feature(iter_array_chunks)]
let x = [1,2,3,4,5].into_iter().array_chunks::<2>();
let mut rem = x.into_remainder();
assert_eq!(rem.next(), Some(5));
assert_eq!(rem.next(), None);

Trait Implementations

impl<I, const N: usize> DoubleEndedIterator for ArrayChunks<I, N> where I: DoubleEndedIterator + ExactSizeIterator,

fn next_back(&mut self) -> Option<Self::Item>
fn try_rfold<B, F, R>(&mut self, init: B, f: F) -> R
where
    Self: Sized,
    F: FnMut(B, Self::Item) -> R,
    R: Try<Output = B>,
fn rfold<AAA, FFF>(self, init: AAA, fold: FFF) -> AAA
where
    FFF: FnMut(AAA, Self::Item) -> AAA,

impl<I, const N: usize> ExactSizeIterator for ArrayChunks<I, N> where I: ExactSizeIterator,

fn len(&self) -> usize
fn is_empty(&self) -> bool

impl<I, const N: usize> FusedIterator for ArrayChunks<I, N> where I: FusedIterator,

impl<I, const N: usize> Iterator for ArrayChunks<I, N> where I: Iterator,

type Item = [<I as Iterator>::Item; N];
fn next(&mut self) -> Option<Self::Item>
fn size_hint(&self) -> (usize, Option<usize>)
fn count(self) -> usize
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>,
fn fold<B, F>(self, init: B, f: F) -> B
where
    Self: Sized,
    F: FnMut(B, Self::Item) -> B,

impl<I, const N: usize> SourceIter for ArrayChunks<I, N> where I: SourceIter + Iterator,

type Source = <I as SourceIter>::Source;
unsafe fn as_inner(&mut self) -> &mut I::Source

impl<I, const N: usize> SpecFold for ArrayChunks<I, N> where I: Iterator + TrustedRandomAccessNoCoerce,

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

impl<I, const N: usize> SpecFold for ArrayChunks<I, N> where I: Iterator,

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

impl<I, const N: usize> TrustedFused for ArrayChunks<I, N> where I: TrustedFused + Iterator,

impl<I: Clone + Iterator, const N: usize> Clone for ArrayChunks<I, N> where I::Item: Clone,

fn clone(&self) -> ArrayChunks<I, N>

impl<I: Debug + Iterator, const N: usize> Debug for ArrayChunks<I, N> where I::Item: Debug,

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

impl<I: InPlaceIterable + Iterator, const N: usize> InPlaceIterable for ArrayChunks<I, N>

const EXPAND_BY: Option<NonZero<usize>> = I::EXPAND_BY;
const MERGE_BY: Option<NonZero<usize>> = _;

Auto Trait Implementations

impl<I, const N: usize> Freeze for ArrayChunks<I, N> where I: Freeze, Option<IntoIter<<I as Iterator>::Item, N>>: Freeze,

impl<I, const N: usize> RefUnwindSafe for ArrayChunks<I, N> where I: RefUnwindSafe, Option<IntoIter<<I as Iterator>::Item, N>>: RefUnwindSafe,

impl<I, const N: usize> Send for ArrayChunks<I, N> where I: Send, Option<IntoIter<<I as Iterator>::Item, N>>: Send,

impl<I, const N: usize> Sync for ArrayChunks<I, N> where I: Sync, Option<IntoIter<<I as Iterator>::Item, N>>: Sync,

impl<I, const N: usize> Unpin for ArrayChunks<I, N> where I: Unpin, Option<IntoIter<<I as Iterator>::Item, N>>: Unpin,

impl<I, const N: usize> UnsafeUnpin for ArrayChunks<I, N> where I: UnsafeUnpin, Option<IntoIter<<I as Iterator>::Item, N>>: UnsafeUnpin,

impl<I, const N: usize> UnwindSafe for ArrayChunks<I, N> where I: UnwindSafe, Option<IntoIter<<I as Iterator>::Item, N>>: UnwindSafe,

Blanket Implementations

impl<I> IntoIterator for ArrayChunks<I, N> where I: Iterator,

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

impl<T> Any for ArrayChunks<I, N> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for ArrayChunks<I, N> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for ArrayChunks<I, N> where T: ?Sized,

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

impl<T> CloneToUninit for ArrayChunks<I, N> where T: Clone,

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

impl<T> From<T> for ArrayChunks<I, N>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for ArrayChunks<I, N> where T: ?Sized,

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

impl<T> SizedTypeProperties for ArrayChunks<I, N>

impl<T, U> Into<U> for ArrayChunks<I, N> 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 ArrayChunks<I, N> 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 ArrayChunks<I, N> where U: TryFrom<T>,

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