konst::slice

Function as_chunks

Source
pub const fn as_chunks<'a, T, const N: usize>(this: &[T]) -> (&[[T; N]], &[T])
Expand description

Const equivalent of <[T]>::as_chunks

The equivalent std function is unstable as of Rust 1.83.0.

§Panics

Panics if N == 0.

§Example

use konst::slice;

let (arrs, rem) = slice::as_chunks::<_, 3>(&[2u32, 3, 5, 8, 13, 21, 34, 55]);

assert_eq!(arrs, &[[2, 3, 5], [8, 13, 21]][..]);
assert_eq!(rem, &[34, 55][..])