Function winter_utils::group_slice_elements[][src]

pub fn group_slice_elements<T, const N: usize>(source: &[T]) -> &[[T; N]]
Notable traits for &'_ mut [u8]
impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
Expand description

Transmutes a slice of n elements into a slice of n / N elements, each of which is an array of N elements.

This function just re-interprets the underlying memory and is thus zero-copy.

Panics

Panics if n is not divisible by N.

Example

let a = [0_u32, 1, 2, 3, 4, 5, 6, 7];
let b: &[[u32; 2]] = group_slice_elements(&a);

assert_eq!(&[[0, 1], [2, 3], [4, 5], [6, 7]], b);