move semantics done
This commit is contained in:
parent
caac1b3bfa
commit
0b66b2945a
exercises/move_semantics
|
@ -1,12 +1,10 @@
|
|||
// move_semantics1.rs
|
||||
// Make me compile! Execute `rustlings hint move_semantics1` for hints :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let vec0 = Vec::new();
|
||||
|
||||
let vec1 = fill_vec(vec0);
|
||||
let mut vec1 = fill_vec(vec0);
|
||||
|
||||
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||||
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
// Make me compile without changing line 13!
|
||||
// Execute `rustlings hint move_semantics2` for hints :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let vec0 = Vec::new();
|
||||
let vec0 = Vec::<i32>::new();
|
||||
let vec2 = Vec::<i32>::new();
|
||||
|
||||
let mut vec1 = fill_vec(vec0);
|
||||
|
||||
let mut vec1 = fill_vec(vec2);
|
||||
|
||||
// Do not change the following line!
|
||||
println!("{} has length {} content `{:?}`", "vec0", vec0.len(), vec0);
|
||||
|
|
|
@ -3,10 +3,8 @@
|
|||
// (no lines with multiple semicolons necessary!)
|
||||
// Execute `rustlings hint move_semantics3` for hints :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let vec0 = Vec::new();
|
||||
let mut vec0 = Vec::<i32>::new();
|
||||
|
||||
let mut vec1 = fill_vec(vec0);
|
||||
|
||||
|
@ -17,7 +15,7 @@ fn main() {
|
|||
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||||
}
|
||||
|
||||
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
||||
fn fill_vec( mut vec: Vec<i32>) -> Vec<i32> {
|
||||
vec.push(22);
|
||||
vec.push(44);
|
||||
vec.push(66);
|
||||
|
|
|
@ -2,12 +2,8 @@
|
|||
// Refactor this code so that instead of having `vec0` and creating the vector
|
||||
// in `fn main`, we create it within `fn fill_vec` and transfer the
|
||||
// freshly created vector from fill_vec to its caller.
|
||||
// Execute `rustlings hint move_semantics4` for hints!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let vec0 = Vec::new();
|
||||
let vec0 = Vec::<i32>::new();
|
||||
|
||||
let mut vec1 = fill_vec(vec0);
|
||||
|
||||
|
@ -19,7 +15,7 @@ fn main() {
|
|||
}
|
||||
|
||||
// `fill_vec()` no longer takes `vec: Vec<i32>` as argument
|
||||
fn fill_vec() -> Vec<i32> {
|
||||
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
||||
let mut vec = vec;
|
||||
|
||||
vec.push(22);
|
||||
|
|
Loading…
Reference in a new issue