-
| Hello, I am on move_semantics1.rs and this was the solution I came to: // TODO: Fix the compiler error in this function. fn fill_vec(mut vec: Vec<i32>) -> Vec<i32> { vec.push(88); vec }Since the TODO was to just fix the compiler error, I was assuming that this is fine, but when I checked out the solution, it uses the fn fill_vec(vec: Vec<i32>) -> Vec<i32> { let mut vec = vec; // ^^^ added vec.push(88); vec }While I understand that the two solutions are different, I am having a hard time understanding the situation where you would want to shadow the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
| This exercise demonstrates that you can declare something as mutable when you own it, even if it was immutable.
|
Beta Was this translation helpful? Give feedback.
This exercise demonstrates that you can declare something as mutable when you own it, even if it was immutable.
move_semantics3recommends exactly what you did by addingmutto the parameter. This is the idiomatic way.