std-function

std::array::from_mut

Adapt exclusive access to a value into exclusive access to a one-element array, so array-shaped APIs can update it. Expected stdout (not executed): 7 Common mistake: Assuming the mutation affects a separate copy.

Formal Syntax & Structure

rust syntaxrust
std::array::from_mut(&mut value) -> &mut [T; 1]

Working Example

Example Snippetrust
fn main() {    let mut count = 4;    std::array::from_mut(&mut count)[0] += 3;    println!("{count}");}
Rust Reference