You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// `fill_vec()` no longer takes `vec: Vec<i32>` as argument - don't change this!
fnfill_vec() -> Vec<i32>{
// Instead, let's create and fill the Vec in here - how do you do that?
letmut vec = vec;
vec.push(88);
vec
}
Proposed Change:
#[test]fnmain(){// No changes should be made in the main functionlet vec1 = fill_vec();assert_eq!(vec1, vec![22, 44, 66, 88]);}// `fill_vec()` no longer takes `vec: Vec<i32>` as argumentfnfill_vec() -> ??? {// Instead, let's create and fill the Vec in here - how do you do that?letmut vec = ???
vec.push(88);
vec
}
The purpose of this exercise, as I understand it, is to help users grasp the concept of ownership and how values can be returned with ownership transferred back to the caller.
Removed the declaration and usage of vec0 as it doesn't serve any purpose in this exercise. When I was solving this exercise, I thought I had to do something with it but at last, I found I had to remove it.
Refactored the declaration of vec in fill_vec to guide learners towards what they should modify.
Ask the user to determine the return type of fill_vec to help learners understand that they should return a value with ownership instead of a reference.
Added a comment in main to instruct learners not to change the main function, allowing them to focus on modifying fill_vec.
This proposal might still have some imperfections so I opened this issue. Feel free to share your ideas.
The text was updated successfully, but these errors were encountered:
Current:
rustlings/exercises/06_move_semantics/move_semantics4.rs
Lines 12 to 29 in 258ff6f
Proposed Change:
The purpose of this exercise, as I understand it, is to help users grasp the concept of ownership and how values can be returned with ownership transferred back to the caller.
vec0
as it doesn't serve any purpose in this exercise. When I was solving this exercise, I thought I had to do something with it but at last, I found I had to remove it.vec
infill_vec
to guide learners towards what they should modify.fill_vec
to help learners understand that they should return a value with ownership instead of a reference.main
to instruct learners not to change themain
function, allowing them to focus on modifyingfill_vec
.This proposal might still have some imperfections so I opened this issue. Feel free to share your ideas.
The text was updated successfully, but these errors were encountered: