Function konst::slice::chunks_exact

source ·
pub const fn chunks_exact<T>(
    slice: &[T],
    chunk_size: usize,
) -> ChunksExact<'_, T>
Expand description

Const equivalent of <[T]>::chunks_exact

§Panics

Panics if chunk_size == 0.

§Example

use konst::{option, slice};

const FOUND: [&[u8]; 3] = {
    let iter = slice::chunks_exact(&[3, 5, 8, 13, 21, 34, 55, 89], 3);
    let (elem0, iter) = option::unwrap!(iter.next());
    let (elem1, iter) = option::unwrap!(iter.next());
    [elem0, elem1, iter.remainder()]
};

let expected: [&[u8]; 3] = [&[3u8, 5, 8], &[13, 21, 34], &[55, 89]];

assert_eq!(FOUND, expected);