rustlings
rustlings copied to clipboard
move_semantics3 solution places mut in front of parameter without explaining it is possible
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.