diff options
Diffstat (limited to 'rustlings/exercises/12_options/options1.rs')
| -rw-r--r-- | rustlings/exercises/12_options/options1.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/rustlings/exercises/12_options/options1.rs b/rustlings/exercises/12_options/options1.rs index d0c412a..be97952 100644 --- a/rustlings/exercises/12_options/options1.rs +++ b/rustlings/exercises/12_options/options1.rs @@ -3,7 +3,13 @@ // someone eats it all, so no ice cream is left (value 0). Return `None` if // `hour_of_day` is higher than 23. fn maybe_ice_cream(hour_of_day: u16) -> Option<u16> { - // TODO: Complete the function body. + if hour_of_day >= 24 { + return None; + } + if hour_of_day >= 22 { + return Some(0); + } + Some(5) } fn main() { @@ -18,7 +24,7 @@ mod tests { fn raw_value() { // TODO: Fix this test. How do you get the value contained in the // Option? - let ice_creams = maybe_ice_cream(12); + let ice_creams = maybe_ice_cream(12).unwrap(); assert_eq!(ice_creams, 5); // Don't change this line. } |