pub const fn flatten<T, const N: usize>(vals: &[[T; N]]) -> &[T]
Expand description
Takes a &[[T; N]]
, and flattens it to a &[T]
.
§Panics
This panics if the length of the resulting slice would overflow a usize
.
This is only possible when flattening a slice of arrays of zero-sized
types, and thus tends to be irrelevant in practice. If
size_of::<T>() > 0
, this will never panic.
§Examples
assert_eq!(array_util::flatten(&[[1, 2, 3], [4, 5, 6]]), &[1, 2, 3, 4, 5, 6]);
assert_eq!(
array_util::flatten(&[[1, 2, 3], [4, 5, 6]]),
array_util::flatten(&[[1, 2], [3, 4], [5, 6]]),
);
let slice_of_empty_arrays: &[[i32; 0]] = &[[], [], [], [], []];
assert!(array_util::flatten(&slice_of_empty_arrays).is_empty());
let empty_slice_of_arrays: &[[u32; 10]] = &[];
assert!(array_util::flatten(&empty_slice_of_arrays).is_empty());