diff --git a/exercises/move_semantics/move_semantics1.rs b/exercises/move_semantics/move_semantics1.rs index 710d20d8..e2235f03 100644 --- a/exercises/move_semantics/move_semantics1.rs +++ b/exercises/move_semantics/move_semantics1.rs @@ -3,18 +3,22 @@ // Execute `rustlings hint move_semantics1` or use the `hint` watch subcommand // for a hint. -// 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); vec1.push(88); println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1); + + let mut vec0 = vec1.clone(); + + println!("{} has length {} content `{:?}`", "vec0", vec0.len(), vec0); + + println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1); } fn fill_vec(vec: Vec) -> Vec { diff --git a/exercises/move_semantics/move_semantics2.rs b/exercises/move_semantics/move_semantics2.rs index 72d37fa4..a0e16363 100644 --- a/exercises/move_semantics/move_semantics2.rs +++ b/exercises/move_semantics/move_semantics2.rs @@ -7,18 +7,28 @@ // Execute `rustlings hint move_semantics2` or use the `hint` watch subcommand // for a hint. -// I AM NOT DONE - fn main() { let vec0 = Vec::new(); let mut vec1 = fill_vec(vec0); - println!("{} has length {}, with contents: `{:?}`", "vec0", vec0.len(), vec0); + let mut vec0 = vec1.clone(); + + println!( + "{} has length {}, with contents: `{:?}`", + "vec0", + vec0.len(), + vec0 + ); vec1.push(88); - println!("{} has length {}, with contents `{:?}`", "vec1", vec1.len(), vec1); + println!( + "{} has length {}, with contents `{:?}`", + "vec1", + vec1.len(), + vec1 + ); } fn fill_vec(vec: Vec) -> Vec { diff --git a/exercises/move_semantics/move_semantics3.rs b/exercises/move_semantics/move_semantics3.rs index ea214934..0ff27c59 100644 --- a/exercises/move_semantics/move_semantics3.rs +++ b/exercises/move_semantics/move_semantics3.rs @@ -6,8 +6,6 @@ // Execute `rustlings hint move_semantics3` or use the `hint` watch subcommand // for a hint. -// I AM NOT DONE - fn main() { let vec0 = Vec::new(); @@ -20,9 +18,10 @@ fn main() { println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1); } -fn fill_vec(vec: Vec) -> Vec { +fn fill_vec(mut vec: Vec) -> Vec { vec.push(22); vec.push(44); + vec.push(44); vec.push(66); vec diff --git a/exercises/move_semantics/move_semantics4.rs b/exercises/move_semantics/move_semantics4.rs index 75a3b6bd..12d47f99 100644 --- a/exercises/move_semantics/move_semantics4.rs +++ b/exercises/move_semantics/move_semantics4.rs @@ -7,12 +7,8 @@ // Execute `rustlings hint move_semantics4` or use the `hint` watch subcommand // for a hint. -// I AM NOT DONE - fn main() { - let vec0 = Vec::new(); - - let mut vec1 = fill_vec(vec0); + let mut vec1 = fill_vec(); println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1); @@ -23,7 +19,7 @@ fn main() { // `fill_vec()` no longer takes `vec: Vec` as argument fn fill_vec() -> Vec { - let mut vec = vec; + let mut vec = Vec::new(); vec.push(22); vec.push(44); diff --git a/exercises/move_semantics/move_semantics5.rs b/exercises/move_semantics/move_semantics5.rs index 68db09eb..03f025a9 100644 --- a/exercises/move_semantics/move_semantics5.rs +++ b/exercises/move_semantics/move_semantics5.rs @@ -6,13 +6,13 @@ // Execute `rustlings hint move_semantics5` or use the `hint` watch subcommand // for a hint. -// I AM NOT DONE fn main() { let mut x = 100; - let y = &mut x; - let z = &mut x; + let mut y = &mut x; *y += 100; + // let mut z = y; + let mut z = &mut x; *z += 1000; assert_eq!(x, 1200); } diff --git a/exercises/move_semantics/move_semantics6.rs b/exercises/move_semantics/move_semantics6.rs index cace4ca6..13fe56e8 100644 --- a/exercises/move_semantics/move_semantics6.rs +++ b/exercises/move_semantics/move_semantics6.rs @@ -5,24 +5,23 @@ // Execute `rustlings hint move_semantics6` or use the `hint` watch subcommand // for a hint. -// I AM NOT DONE - fn main() { let data = "Rust is great!".to_string(); - get_char(data); + // get_char(data.clone()); + get_char(&data); string_uppercase(&data); } // Should not take ownership -fn get_char(data: String) -> char { +fn get_char(data: &String) -> char { data.chars().last().unwrap() } // Should take ownership fn string_uppercase(mut data: &String) { - data = &data.to_uppercase(); + let mut data = &data.to_uppercase(); println!("{}", data); } diff --git a/exercises/primitive_types/primitive_types1.rs b/exercises/primitive_types/primitive_types1.rs index e1cf52a2..92c15b59 100644 --- a/exercises/primitive_types/primitive_types1.rs +++ b/exercises/primitive_types/primitive_types1.rs @@ -6,7 +6,6 @@ // Execute `rustlings hint primitive_types1` or use the `hint` watch subcommand // for a hint. -// I AM NOT DONE fn main() { // Booleans (`bool`) @@ -16,7 +15,8 @@ fn main() { println!("Good morning!"); } - let // Finish the rest of this line like the example! Or make it be false! + let is_evening = !is_morning; + // Finish the rest of this line like the example! Or make it be false! if is_evening { println!("Good evening!"); } diff --git a/exercises/primitive_types/primitive_types2.rs b/exercises/primitive_types/primitive_types2.rs index fcc9705a..e1bbc5da 100644 --- a/exercises/primitive_types/primitive_types2.rs +++ b/exercises/primitive_types/primitive_types2.rs @@ -6,8 +6,6 @@ // Execute `rustlings hint primitive_types2` or use the `hint` watch subcommand // for a hint. -// I AM NOT DONE - fn main() { // Characters (`char`) @@ -22,7 +20,10 @@ fn main() { println!("Neither alphabetic nor numeric!"); } - let // Finish this line like the example! What's your favorite character? + let your_character = 'B'; + let your_character = '1'; + let your_character = '≈'; + // Finish this line like the example! What's your favorite character? // Try a letter, try a number, try a special character, try a character // from a different language than your own, try an emoji! if your_character.is_alphabetic() { diff --git a/exercises/primitive_types/primitive_types3.rs b/exercises/primitive_types/primitive_types3.rs index 06a7a621..9d90005d 100644 --- a/exercises/primitive_types/primitive_types3.rs +++ b/exercises/primitive_types/primitive_types3.rs @@ -5,10 +5,8 @@ // Execute `rustlings hint primitive_types3` or use the `hint` watch subcommand // for a hint. -// I AM NOT DONE - fn main() { - let a = ??? + let a = ["1"; 101]; if a.len() >= 100 { println!("Wow, that's a big array!"); diff --git a/exercises/primitive_types/primitive_types4.rs b/exercises/primitive_types/primitive_types4.rs index d44d8776..be863098 100644 --- a/exercises/primitive_types/primitive_types4.rs +++ b/exercises/primitive_types/primitive_types4.rs @@ -5,13 +5,11 @@ // Execute `rustlings hint primitive_types4` or use the `hint` watch subcommand // for a hint. -// I AM NOT DONE - #[test] fn slice_out_of_array() { let a = [1, 2, 3, 4, 5]; - let nice_slice = ??? + let nice_slice = &a[1..4]; assert_eq!([2, 3, 4], nice_slice) } diff --git a/exercises/primitive_types/primitive_types5.rs b/exercises/primitive_types/primitive_types5.rs index f646986e..7a330445 100644 --- a/exercises/primitive_types/primitive_types5.rs +++ b/exercises/primitive_types/primitive_types5.rs @@ -5,11 +5,9 @@ // Execute `rustlings hint primitive_types5` or use the `hint` watch subcommand // for a hint. -// I AM NOT DONE - fn main() { let cat = ("Furry McFurson", 3.5); - let /* your pattern here */ = cat; + let (name, age) = cat; println!("{} is {} years old.", name, age); } diff --git a/exercises/primitive_types/primitive_types6.rs b/exercises/primitive_types/primitive_types6.rs index 07cc46c6..16bf0eab 100644 --- a/exercises/primitive_types/primitive_types6.rs +++ b/exercises/primitive_types/primitive_types6.rs @@ -6,14 +6,11 @@ // Execute `rustlings hint primitive_types6` or use the `hint` watch subcommand // for a hint. -// I AM NOT DONE - #[test] fn indexing_tuple() { let numbers = (1, 2, 3); // Replace below ??? with the tuple indexing syntax. - let second = ???; + let second = numbers.1; - assert_eq!(2, second, - "This is not the 2nd number in the tuple!") + assert_eq!(2, second, "This is not the 2nd number in the tuple!") } diff --git a/exercises/vecs/vecs1.rs b/exercises/vecs/vecs1.rs index 65b7a7f8..646da08f 100644 --- a/exercises/vecs/vecs1.rs +++ b/exercises/vecs/vecs1.rs @@ -7,11 +7,15 @@ // // 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 mut v: Vec = Vec::new(); // TODO: declare your vector here with the macro for vectors +// v.push(a[0]); +// v.push(a[1]); +// v.push(a[2]); +// v.push(a[3]); + let v:Vec = vec![10,20,30,40]; (a, v) } diff --git a/exercises/vecs/vecs2.rs b/exercises/vecs/vecs2.rs index e92c970a..b7f1c72a 100644 --- a/exercises/vecs/vecs2.rs +++ b/exercises/vecs/vecs2.rs @@ -7,13 +7,11 @@ // // 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 *= 2; } // At this point, `v` should be equal to [4, 8, 12, 16, 20]. @@ -21,11 +19,13 @@ fn vec_loop(mut v: Vec) -> Vec { } 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! - ??? - }).collect() + 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() } #[cfg(test)] diff --git a/temp_49224_ThreadId1 b/temp_49224_ThreadId1 new file mode 100755 index 00000000..aed36879 Binary files /dev/null and b/temp_49224_ThreadId1 differ