From 0b66b2945af11fa881a75efb8ed66e028767f9ae Mon Sep 17 00:00:00 2001 From: Simon Halimi <halimisimon@gmail.com> Date: Tue, 13 Apr 2021 15:03:46 +0200 Subject: [PATCH] move semantics done --- exercises/move_semantics/move_semantics1.rs | 4 +--- exercises/move_semantics/move_semantics2.rs | 8 ++++---- exercises/move_semantics/move_semantics3.rs | 6 ++---- exercises/move_semantics/move_semantics4.rs | 8 ++------ 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/exercises/move_semantics/move_semantics1.rs b/exercises/move_semantics/move_semantics1.rs index e2f5876..a95f851 100644 --- a/exercises/move_semantics/move_semantics1.rs +++ b/exercises/move_semantics/move_semantics1.rs @@ -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); diff --git a/exercises/move_semantics/move_semantics2.rs b/exercises/move_semantics/move_semantics2.rs index bd21fbb..8686022 100644 --- a/exercises/move_semantics/move_semantics2.rs +++ b/exercises/move_semantics/move_semantics2.rs @@ -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); diff --git a/exercises/move_semantics/move_semantics3.rs b/exercises/move_semantics/move_semantics3.rs index 43fef74..4618f9c 100644 --- a/exercises/move_semantics/move_semantics3.rs +++ b/exercises/move_semantics/move_semantics3.rs @@ -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); diff --git a/exercises/move_semantics/move_semantics4.rs b/exercises/move_semantics/move_semantics4.rs index 2a23c71..80b8cd6 100644 --- a/exercises/move_semantics/move_semantics4.rs +++ b/exercises/move_semantics/move_semantics4.rs @@ -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);