rustlings icon indicating copy to clipboard operation
rustlings copied to clipboard

move_semantics3 solution places mut in front of parameter without explaining it is possible

Open lectrician1 opened this issue 1 year ago • 0 comments

The solution for this

fn main() {
    let vec0 = Vec::new();

    let mut vec1 = fill_vec(vec0);

    println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);

    vec1.push(88);

    println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
}

fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
    vec.push(22);
    vec.push(44);
    vec.push(66);

    vec
}

is to put a mut in front of the vec parameter in fill_vec.

However, neither the references or ownership Rust book pages explain that placing mut in front of a parameter is possible. I was stuck on this until I looked at an answer key.

lectrician1 avatar Apr 16 '23 19:04 lectrician1