[][src]Struct array_tools::ArrayChunks

pub struct ArrayChunks<T, A: FixedSizeArray<T>, CHUNK: FixedSizeArray<T>, STUMP: FixedSizeArray<T>> { /* fields omitted */ }

An iterator yielding chunks ("subarrays") of requested size, akin to core::slice::Chunks.

If array can't be evenly divided into chunks, the last item will be a so called stump - an array that contains remaining number of items, insufficient to form a chunk.

As item type, array type, chunk type and stump type must be known at compile time, there are 4 generic parameters that represent them.

  1. The first generic parameter must match input array item type.
  2. The second generic parameter must match input array type. Item type must match first parameter, size may be whatever pleases you.
  3. The third generic parameter is chunk - an array. Item type must match first parameter, size may be whatever pleases you.
  4. The fourth generic parameter is stump - an array. Item type must match first parameter, size must be array_length % chunk_length.

Examples

use array_tools::{ArrayChunk, ArrayChunks};
use core::marker::PhantomData;
let array = [1u64, 2, 3, 4, 5, 6, 7, 8];

// Divide array `[u64; 8]` into `[u64; 3]` chunks. It can't be divided evenly, so last item
// will be stump of type `[u64; 2]`.
let mut chunks: ArrayChunks<u64, [u64; 8], [u64; 3], [u64; 2]> = ArrayChunks::new(array);

assert_eq!(chunks.next(), Some(ArrayChunk::Chunk([1u64, 2, 3], PhantomData)));
assert_eq!(chunks.next(), Some(ArrayChunk::Chunk([4u64, 5, 6], PhantomData)));
assert_eq!(chunks.next(), Some(ArrayChunk::Stump([7u64, 8], PhantomData)));
assert_eq!(chunks.next(), None);
use array_tools::{ArrayChunk, ArrayChunks};
use core::marker::PhantomData;
let array = [1u64, 2, 3, 4, 5, 6, 7, 8];

// Divide array `[u64; 8]` into `[u64; 2]` chunks. It *can* be divided evenly, so stump size is
// 0 and it won't ever be yielded.
let mut chunks: ArrayChunks<u64, [u64; 8], [u64; 2], [u64; 0]> = ArrayChunks::new(array);
assert_eq!(chunks.next(), Some(ArrayChunk::Chunk([1u64, 2], PhantomData)));
assert_eq!(chunks.next(), Some(ArrayChunk::Chunk([3u64, 4], PhantomData)));
assert_eq!(chunks.next(), Some(ArrayChunk::Chunk([5u64, 6], PhantomData)));
assert_eq!(chunks.next(), Some(ArrayChunk::Chunk([7u64, 8], PhantomData)));
assert_eq!(chunks.next(), None);

Methods

impl<T, A: FixedSizeArray<T>, CHUNK: FixedSizeArray<T>, STUMP: FixedSizeArray<T>> ArrayChunks<T, A, CHUNK, STUMP>[src]

Important traits for ArrayChunks<T, A, CHUNK, STUMP>
pub fn new(array: A) -> ArrayChunks<T, A, CHUNK, STUMP>[src]

Creates a new ArrayChunks iterator.

Panics

If chunk size is 0. If stump size is not valid (See structure documentation).

Note

Though currently this function panics if chunk size is 0 and/or stump size is not valid, this behavior most certainly will be changed in future to perform these checks at compile time.

Trait Implementations

impl<T, A: FixedSizeArray<T>, CHUNK: FixedSizeArray<T>, STUMP: FixedSizeArray<T>> Debug for ArrayChunks<T, A, CHUNK, STUMP> where
    T: Debug
[src]

impl<T, A: FixedSizeArray<T>, CHUNK: FixedSizeArray<T>, STUMP: FixedSizeArray<T>> PartialEq<ArrayChunks<T, A, CHUNK, STUMP>> for ArrayChunks<T, A, CHUNK, STUMP> where
    T: PartialEq
[src]

impl<T, A: FixedSizeArray<T>, CHUNK: FixedSizeArray<T>, STUMP: FixedSizeArray<T>> Eq for ArrayChunks<T, A, CHUNK, STUMP> where
    T: Eq
[src]

impl<T, A: FixedSizeArray<T>, CHUNK: FixedSizeArray<T>, STUMP: FixedSizeArray<T>> DoubleEndedIterator for ArrayChunks<T, A, CHUNK, STUMP>[src]

impl<T, A: FixedSizeArray<T>, CHUNK: FixedSizeArray<T>, STUMP: FixedSizeArray<T>> Iterator for ArrayChunks<T, A, CHUNK, STUMP>[src]

type Item = ArrayChunk<T, CHUNK, STUMP>

The type of the elements being iterated over.

impl<T, A: FixedSizeArray<T>, CHUNK: FixedSizeArray<T>, STUMP: FixedSizeArray<T>> Clone for ArrayChunks<T, A, CHUNK, STUMP> where
    T: Clone
[src]

Auto Trait Implementations

impl<T, A, CHUNK, STUMP> Unpin for ArrayChunks<T, A, CHUNK, STUMP> where
    A: Unpin,
    CHUNK: Unpin,
    STUMP: Unpin,
    T: Unpin

impl<T, A, CHUNK, STUMP> Send for ArrayChunks<T, A, CHUNK, STUMP> where
    A: Send,
    CHUNK: Send,
    STUMP: Send,
    T: Send

impl<T, A, CHUNK, STUMP> Sync for ArrayChunks<T, A, CHUNK, STUMP> where
    A: Sync,
    CHUNK: Sync,
    STUMP: Sync,
    T: Sync

Blanket Implementations

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]