diff --git a/exercises/enums/enums3.rs b/exercises/enums/enums3.rs index d423e06e..6f3ab78b 100644 --- a/exercises/enums/enums3.rs +++ b/exercises/enums/enums3.rs @@ -64,7 +64,7 @@ mod tests { }; state.process(Message::ChangeColor(255, 0, 255)); state.process(Message::Echo(String::from("hello world"))); - state.process(Message::Move(Point{ x: 10, y: 15 })); + state.process(Message::Move{ x: 10, y: 15 }); state.process(Message::Quit); assert_eq!(state.color, (255, 0, 255)); diff --git a/exercises/error_handling/result1.rs b/exercises/error_handling/result1.rs index b978001b..f555baef 100644 --- a/exercises/error_handling/result1.rs +++ b/exercises/error_handling/result1.rs @@ -1,8 +1,6 @@ // result1.rs // Make this test pass! Execute `rustlings hint result1` for hints :) -// I AM NOT DONE - #[derive(PartialEq, Debug)] struct PositiveNonzeroInteger(u64); @@ -14,7 +12,14 @@ enum CreationError { impl PositiveNonzeroInteger { fn new(value: i64) -> Result { - Ok(PositiveNonzeroInteger(value as u64)) + if value > 1 { + Ok(PositiveNonzeroInteger(value as u64)) + } else if value == 0 { + Err(CreationError::Zero) + } else { + Err(CreationError::Negative) + } + } } diff --git a/exercises/if/if2.rs b/exercises/if/if2.rs index 80effbdf..545083a3 100644 --- a/exercises/if/if2.rs +++ b/exercises/if/if2.rs @@ -4,13 +4,13 @@ // Step 2: Get the bar_for_fuzz and default_to_baz tests passing! // Execute the command `rustlings hint if2` if you want a hint :) -// I AM NOT DONE - pub fn fizz_if_foo(fizzish: &str) -> &str { if fizzish == "fizz" { "foo" + } else if fizzish == "fuzz" { + "bar" } else { - 1 + "baz" } } diff --git a/exercises/option/option1.rs b/exercises/option/option1.rs index 2a6c2f77..40cf2fe7 100644 --- a/exercises/option/option1.rs +++ b/exercises/option/option1.rs @@ -1,23 +1,23 @@ // option1.rs // Make me compile! Execute `rustlings hint option1` for hints -// I AM NOT DONE - // you can modify anything EXCEPT for this function's sig fn print_number(maybe_number: Option) { println!("printing: {}", maybe_number.unwrap()); } fn main() { - print_number(13); - print_number(99); + print_number(Option::Some(13)); + print_number(Option::Some(99)); - let mut numbers: [Option; 5]; + let mut numbers: [Option; 5] = [ + Option::Some(0), Option::Some(0), Option::Some(0), Option::Some(0), Option::Some(0) + ]; for iter in 0..5 { let number_to_add: u16 = { ((iter * 5) + 2) / (4 * 16) }; - numbers[iter as usize] = number_to_add; + numbers[iter as usize] = Option::Some(number_to_add); } } diff --git a/exercises/option/option2.rs b/exercises/option/option2.rs index a1517d7c..c9ba5c3f 100644 --- a/exercises/option/option2.rs +++ b/exercises/option/option2.rs @@ -1,12 +1,10 @@ // option2.rs // Make me compile! Execute `rustlings hint option2` for hints -// I AM NOT DONE - fn main() { let optional_value = Some(String::from("rustlings")); // TODO: Make this an if let statement whose value is "Some" type - value = optional_value { + if let Some(value) = optional_value { println!("the value of optional value is: {}", value); } else { println!("The optional value doesn't contain anything!"); @@ -19,7 +17,7 @@ fn main() { // TODO: make this a while let statement - remember that vector.pop also adds another layer of Option // You can stack `Option`'s into while let and if let - value = optional_values_vec.pop() { + while let Some(Some(value)) = optional_values_vec.pop() { println!("current value: {}", value); } } diff --git a/exercises/structs/structs3.rs b/exercises/structs/structs3.rs index 77cc154b..663e1c4c 100644 --- a/exercises/structs/structs3.rs +++ b/exercises/structs/structs3.rs @@ -3,8 +3,6 @@ // exercise we have defined the Package struct and we want to test some logic attached to it, // make the code compile and the tests pass! If you have issues execute `rustlings hint structs3` -// I AM NOT DONE - #[derive(Debug)] struct Package { from: String, @@ -15,18 +13,20 @@ struct Package { impl Package { fn new(from: String, to: String, weight: f32) -> Package { if weight <= 0.0 { - // Something goes here... + panic!("Package is lighter then air!") } else { return Package {from, to, weight}; } } - fn is_international(&self) -> ??? { + fn is_international(&self) -> bool { // Something goes here... + self.from != self.to } - fn get_fees(&self, cost_per_kg: f32) -> ??? { + fn get_fees(&self, cost_per_kg: f32) -> f32 { // Something goes here... + self.weight * cost_per_kg } } @@ -58,7 +58,7 @@ mod tests { let country_from = String::from("Spain"); let country_to = String::from("Spain"); - let country_fee = ???; + let country_fee = 8.0; let package = Package::new(country_from, country_to, 22.0); diff --git a/exercises/variables/variables6.rs b/exercises/variables/variables6.rs index 76afa859..8407754b 100644 --- a/exercises/variables/variables6.rs +++ b/exercises/variables/variables6.rs @@ -1,9 +1,7 @@ // variables5.rs // Make me compile! Execute the command `rustlings hint variables6` if you want a hint :) -// I AM NOT DONE - -const NUMBER = 3; +const NUMBER: u8 = 3; fn main() { println!("Number {}", NUMBER); }