pub fn flatten_mut<T, const N: usize>(vals: &mut [[T; N]]) -> &mut [T]
Expand description
Takes a &mut [[T; N]]
, and flattens it to a &mut [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
fn add_5_to_all(slice: &mut [i32]) {
for i in slice {
*i += 5;
}
}
let mut array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
add_5_to_all(array_util::flatten_mut(&mut array));
assert_eq!(array, [[6, 7, 8], [9, 10, 11], [12, 13, 14]]);