diff --git a/exercises/collections/hashmap1.rs b/exercises/collections/hashmap1.rs index 64b5a7f3..6ba71446 100644 --- a/exercises/collections/hashmap1.rs +++ b/exercises/collections/hashmap1.rs @@ -11,17 +11,19 @@ // Execute the command `rustlings hint hashmap1` if you need // hints. -// I AM NOT DONE use std::collections::HashMap; fn fruit_basket() -> HashMap { - let mut basket = // TODO: declare your hash map here. - - // Two bananas are already given for you :) - basket.insert(String::from("banana"), 2); - + // TODO: declare your hash map here. + let mut basket = HashMap::new(); + // TODO: Put more fruits in your basket here. + // Two bananas are already given for you :) + // Format is basket.insert(String,u32); + basket.insert(String::from("banana"), 2); + basket.insert(String::from("bapple"),4); + basket.insert(String::from("horange"),1); basket } diff --git a/exercises/collections/hashmap2.rs b/exercises/collections/hashmap2.rs index 0abe19ab..94845786 100644 --- a/exercises/collections/hashmap2.rs +++ b/exercises/collections/hashmap2.rs @@ -4,8 +4,9 @@ // represents the name of the fruit and the value represents how many // of that particular fruit is in the basket. You have to put *MORE // THAN 11* fruits in the basket. Three types of fruits - Apple (4), -// Mango (2) and Lychee (5) are already given in the basket. You are -// not allowed to insert any more of these fruits! +// Mango (2) and Lychee (5) are already given in the basket. +// +// You are not allowed to insert any more of these fruits! // // Make me pass the tests! // diff --git a/exercises/collections/vec1.rs b/exercises/collections/vec1.rs index b144fb94..abdbf643 100644 --- a/exercises/collections/vec1.rs +++ b/exercises/collections/vec1.rs @@ -4,11 +4,14 @@ // Make me compile and pass the test! // Execute the command `rustlings hint vec1` if you need hints. -// 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 + // TODO: declare your vector here with the macro for vectors + let mut v: Vec = Vec::new(); // make v a mutable vector! + for i in a.iter() { // making at iterable + v.push(*i) // leting i establish the expected type here + } (a, v) } diff --git a/exercises/collections/vec2.rs b/exercises/collections/vec2.rs index 6595e401..d757c0af 100644 --- a/exercises/collections/vec2.rs +++ b/exercises/collections/vec2.rs @@ -7,12 +7,15 @@ // Execute the command `rustlings hint vec2` if you need // hints. -// I AM NOT DONE fn vec_loop(mut v: Vec) -> Vec { for i in v.iter_mut() { // TODO: Fill this up so that each element in the Vec `v` is // multiplied by 2. + // not so obvious answer, this is because multiplication is a right action in Rust �� + *i = *i*2; + // slick answer below + //*i *= 2; // pythonish: i = 2*i } // At this point, `v` should be equal to [4, 8, 12, 16, 20]. diff --git a/exercises/modules/modules1.rs b/exercises/modules/modules1.rs index 1a2bd0dd..d258c3b7 100644 --- a/exercises/modules/modules1.rs +++ b/exercises/modules/modules1.rs @@ -1,15 +1,14 @@ // modules1.rs // Make me compile! Execute `rustlings hint modules1` for hints :) -// I AM NOT DONE -mod sausage_factory { +mod sausage_factory { // adding pub here doesn't seem to matter . . . If I had to guess, moduless default to public. // Don't let anybody outside of this module see this! fn get_secret_recipe() -> String { String::from("Ginger") } - fn make_sausage() { + pub fn make_sausage() { // adding pub here fixes the problem. I think the lesson is that functions are inherely private, and have to be explicitly made public? get_secret_recipe(); println!("sausage!"); } diff --git a/exercises/modules/modules2.rs b/exercises/modules/modules2.rs index 87f0c458..0b88768c 100644 --- a/exercises/modules/modules2.rs +++ b/exercises/modules/modules2.rs @@ -3,13 +3,12 @@ // 'use' and 'as' keywords. Fix these 'use' statements to make the code compile. // Make me compile! Execute `rustlings hint modules2` for hints :) -// I AM NOT DONE mod delicious_snacks { // TODO: Fix these use statements - use self::fruits::PEAR as ??? - use self::veggies::CUCUMBER as ??? + pub use self::fruits::PEAR as fruit; // so I'm telling this that PEAR is a fruit. + pub use self::veggies::CUCUMBER as veggie; // and here I'm saying CUCUMBER is a veggie. mod fruits { pub const PEAR: &'static str = "Pear"; @@ -25,7 +24,7 @@ mod delicious_snacks { fn main() { println!( "favorite snacks: {} and {}", - delicious_snacks::fruit, - delicious_snacks::veggie + delicious_snacks::fruit, // So we're looking for a delicious snack, but it has to be fruit. + delicious_snacks::veggie // and here it needs to be veggie ); } diff --git a/exercises/modules/modules3.rs b/exercises/modules/modules3.rs index 8eed77df..7059112c 100644 --- a/exercises/modules/modules3.rs +++ b/exercises/modules/modules3.rs @@ -5,10 +5,11 @@ // from the std::time module. Bonus style points if you can do it with one line! // Make me compile! Execute `rustlings hint modules3` for hints :) -// I AM NOT DONE // TODO: Complete this use statement -use ??? +use std::time::{UNIX_EPOCH,SystemTime}; // Hey, I did it! +// pub use std::time::SystemTime as SystemTime; // This is redundant, you just need everything before as +// pub use std::time::UNIX_EPOCH as UNIX_EPOCH; fn main() { match SystemTime::now().duration_since(UNIX_EPOCH) {