diff --git a/exercises/collections/hashmap2.rs b/exercises/collections/hashmap2.rs index 94845786..eb91e4ea 100644 --- a/exercises/collections/hashmap2.rs +++ b/exercises/collections/hashmap2.rs @@ -13,7 +13,6 @@ // Execute the command `rustlings hint hashmap2` if you need // hints. -// I AM NOT DONE use std::collections::HashMap; @@ -35,10 +34,20 @@ fn fruit_basket(basket: &mut HashMap) { Fruit::Pineapple, ]; - for fruit in fruit_kinds { + for fruit in fruit_kinds { // This is sujestive of vectors being iterable // TODO: Put new fruits if not already present. Note that you // are not allowed to put any type of fruit that's already // present! + basket.entry(fruit).or_insert(1); + /* + So, this is just saying "Hey, add 1 + of this fruit if it hasn't already + been added." + */ + + + + } } diff --git a/exercises/error_handling/errors1.rs b/exercises/error_handling/errors1.rs index 5844a497..5526f1c0 100644 --- a/exercises/error_handling/errors1.rs +++ b/exercises/error_handling/errors1.rs @@ -6,14 +6,14 @@ // this function to have. // Execute `rustlings hint errors1` for hints! -// I AM NOT DONE -pub fn generate_nametag_text(name: String) -> Option { + +pub fn generate_nametag_text(name: String) -> Result { if name.len() > 0 { - Some(format!("Hi! My name is {}", name)) + Ok(format!("Hi! My name is {}", name)) } else { // Empty names aren't allowed. - None + Err("`name` was empty; it must be nonempty.".into()) } } @@ -28,7 +28,7 @@ mod tests { fn generates_nametag_text_for_a_nonempty_name() { assert_eq!( generate_nametag_text("Beyoncé".into()), - Some("Hi! My name is Beyoncé".into()) + Ok("Hi! My name is Beyoncé".into()) ); } diff --git a/exercises/quiz2.rs b/exercises/quiz2.rs index de0dce95..b7611ba6 100644 --- a/exercises/quiz2.rs +++ b/exercises/quiz2.rs @@ -7,7 +7,6 @@ // you think each value is. That is, add either `string_slice` or `string` // before the parentheses on each line. If you're right, it will compile! -// I AM NOT DONE fn string_slice(arg: &str) { println!("{}", arg); @@ -17,14 +16,14 @@ fn string(arg: String) { } fn main() { - ???("blue"); - ???("red".to_string()); - ???(String::from("hi")); - ???("rust is fun!".to_owned()); - ???("nice weather".into()); - ???(format!("Interpolation {}", "Station")); - ???(&String::from("abc")[0..1]); - ???(" hello there ".trim()); - ???("Happy Monday!".to_string().replace("Mon", "Tues")); - ???("mY sHiFt KeY iS sTiCkY".to_lowercase()); + string("blue".to_string()); + string("red".to_string()); + string(String::from("hi")); + string("rust is fun!".to_owned()); + string("nice weather".into()); + string(format!("Interpolation {}", "Station")); + string_slice(&String::from("abc")[0..1]); + string_slice(" hello there ".trim()); + string("Happy Monday!".to_string().replace("Mon", "Tues")); + string("mY sHiFt KeY iS sTiCkY".to_lowercase()); } diff --git a/exercises/strings/strings1.rs b/exercises/strings/strings1.rs index 80902444..44d66ea5 100644 --- a/exercises/strings/strings1.rs +++ b/exercises/strings/strings1.rs @@ -2,7 +2,6 @@ // Make me compile without changing the function signature! // Execute `rustlings hint strings1` for hints ;) -// I AM NOT DONE fn main() { let answer = current_favorite_color(); @@ -10,5 +9,5 @@ fn main() { } fn current_favorite_color() -> String { - "blue" + String::from("blue") // String::`F`rom will bugout } diff --git a/exercises/strings/strings2.rs b/exercises/strings/strings2.rs index 5a2ce74a..9e20886c 100644 --- a/exercises/strings/strings2.rs +++ b/exercises/strings/strings2.rs @@ -2,17 +2,16 @@ // Make me compile without changing the function signature! // Execute `rustlings hint strings2` for hints :) -// I AM NOT DONE fn main() { let word = String::from("green"); // Try not changing this line :) - if is_a_color_word(word) { + if is_a_color_word(&*word) { // So I needed to match types here println!("That is a color word I know!"); } else { println!("That is not a color word I know."); } } -fn is_a_color_word(attempt: &str) -> bool { +fn is_a_color_word(attempt: &str) -> bool { // The type specified here needed to be respected when we passed the variable word into the function/ attempt == "green" || attempt == "blue" || attempt == "red" }