From 20a9f727ef6920e79c304c3cde853a9832bafa4d Mon Sep 17 00:00:00 2001 From: Faiizan Hussain <67575585+faiizanhussain@users.noreply.github.com> Date: Tue, 18 Jun 2024 08:33:26 +0000 Subject: [PATCH] 06_4 Done --- exercises/05_vecs/vecs1.rs | 3 +-- exercises/05_vecs/vecs2.rs | 5 ++--- exercises/06_move_semantics/move_semantics1.rs | 4 ++-- exercises/06_move_semantics/move_semantics2.rs | 1 - exercises/06_move_semantics/move_semantics3.rs | 5 ++--- exercises/06_move_semantics/move_semantics4.rs | 11 ++++++----- 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/exercises/05_vecs/vecs1.rs b/exercises/05_vecs/vecs1.rs index 65b7a7f8..8b7d8e19 100644 --- a/exercises/05_vecs/vecs1.rs +++ b/exercises/05_vecs/vecs1.rs @@ -7,11 +7,10 @@ // // Execute `rustlings hint vecs1` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE fn array_and_vec() -> ([i32; 4], Vec) { let a = [10, 20, 30, 40]; // a plain array - let v = // TODO: declare your vector here with the macro for vectors + let v = vec![10, 20, 30, 40];// TODO: declare your vector here with the macro for vectors (a, v) } diff --git a/exercises/05_vecs/vecs2.rs b/exercises/05_vecs/vecs2.rs index e92c970a..7d7d50db 100644 --- a/exercises/05_vecs/vecs2.rs +++ b/exercises/05_vecs/vecs2.rs @@ -7,13 +7,12 @@ // // Execute `rustlings hint vecs2` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE fn vec_loop(mut v: Vec) -> Vec { for element in v.iter_mut() { // TODO: Fill this up so that each element in the Vec `v` is // multiplied by 2. - ??? + *element = *element * 2; } // At this point, `v` should be equal to [4, 8, 12, 16, 20]. @@ -24,7 +23,7 @@ fn vec_map(v: &Vec) -> Vec { v.iter().map(|element| { // TODO: Do the same thing as above - but instead of mutating the // Vec, you can just return the new number! - ??? + element * 2 }).collect() } diff --git a/exercises/06_move_semantics/move_semantics1.rs b/exercises/06_move_semantics/move_semantics1.rs index e0639375..0263b06d 100644 --- a/exercises/06_move_semantics/move_semantics1.rs +++ b/exercises/06_move_semantics/move_semantics1.rs @@ -3,7 +3,7 @@ // Execute `rustlings hint move_semantics1` or use the `hint` watch subcommand // for a hint. -// I AM NOT DONE + #[test] fn main() { @@ -15,7 +15,7 @@ fn main() { } fn fill_vec(vec: Vec) -> Vec { - let vec = vec; + let mut vec = vec; vec.push(88); diff --git a/exercises/06_move_semantics/move_semantics2.rs b/exercises/06_move_semantics/move_semantics2.rs index dc58be50..8972d4c2 100644 --- a/exercises/06_move_semantics/move_semantics2.rs +++ b/exercises/06_move_semantics/move_semantics2.rs @@ -5,7 +5,6 @@ // Execute `rustlings hint move_semantics2` or use the `hint` watch subcommand // for a hint. -// I AM NOT DONE #[test] fn main() { diff --git a/exercises/06_move_semantics/move_semantics3.rs b/exercises/06_move_semantics/move_semantics3.rs index 7152c716..e037de68 100644 --- a/exercises/06_move_semantics/move_semantics3.rs +++ b/exercises/06_move_semantics/move_semantics3.rs @@ -6,18 +6,17 @@ // Execute `rustlings hint move_semantics3` or use the `hint` watch subcommand // for a hint. -// I AM NOT DONE #[test] fn main() { let vec0 = vec![22, 44, 66]; - let vec1 = fill_vec(vec0); + let vec1 = fill_vec(vec0.clone()); assert_eq!(vec1, vec![22, 44, 66, 88]); } -fn fill_vec(vec: Vec) -> Vec { +fn fill_vec(mut vec: Vec) -> Vec { vec.push(88); vec diff --git a/exercises/06_move_semantics/move_semantics4.rs b/exercises/06_move_semantics/move_semantics4.rs index bfc917fa..f6ef1e9e 100644 --- a/exercises/06_move_semantics/move_semantics4.rs +++ b/exercises/06_move_semantics/move_semantics4.rs @@ -7,21 +7,22 @@ // Execute `rustlings hint move_semantics4` or use the `hint` watch subcommand // for a hint. -// I AM NOT DONE #[test] fn main() { - let vec0 = vec![22, 44, 66]; + let mut vec0 = vec![22, 44, 66]; - let vec1 = fill_vec(vec0); + let mut vec1 = fill_vec(); - assert_eq!(vec1, vec![22, 44, 66, 88]); + vec0.append(&mut vec1); + + assert_eq!(vec0, vec![22, 44, 66, 88]); } // `fill_vec()` no longer takes `vec: Vec` as argument - don't change this! fn fill_vec() -> Vec { // Instead, let's create and fill the Vec in here - how do you do that? - let mut vec = vec; + let mut vec = Vec::new(); vec.push(88);