std-method

slice::as_flattened_mut

Borrow a contiguous sequence of fixed-size arrays as one mutable slice. Changes are visible through the original rows after the borrow ends. Expected stdout (not executed): [[1, 2], [9, 4]] Common mistake: Assuming the flat view owns separate storage.

Formal Syntax & Structure

rust syntaxrust
slice_of_arrays.as_flattened_mut()

Working Example

Example Snippetrust
fn main() {    let mut grid = [[1, 2], [3, 4]];    grid.as_flattened_mut()[2] = 9;    println!("{grid:?}");}
Rust Reference