Function konst::slice::array_chunks

source ·
pub const fn array_chunks<'a, T, const N: usize>(
    slice: &'a [T],
) -> ArrayChunks<'a, T, N>
Expand description

Const equivalent of <[T]>::array_chunks

§Panics

Panics if N == 0.

§Example

use konst::slice;

let arr = [3, 5, 8, 13, 21, 34, 55];

let iter = slice::array_chunks::<_, 2>(&arr);

let (val0, iter) = iter.next().unwrap();
let (val1, iter) = iter.next().unwrap();
let (val2, iter) = iter.next().unwrap();

let out: [[u8; 2]; 3] = [*val0, *val1, *val2];
assert_eq!(out, [[3, 5], [8, 13], [21, 34]]);

assert_eq!(iter.remainder(), &[55][..]);