diff options
| author | Hunter Kvalevog <hunter@kvog.sh> | 2026-09-27 11:17:50 -0500 |
|---|---|---|
| committer | Hunter Kvalevog <hunter@kvog.sh> | 2026-09-27 11:17:50 -0500 |
| commit | 1da0f56d76e5d5117eac05af092bf0ab58b14c8f (patch) | |
| tree | 3ef8c1602c5f38d5a33d04d362533a5c5117a932 /rustlings/exercises/12_options/options1.rs | |
| parent | 0fcfd332dd5057a590371c28ed3e6b267f788b76 (diff) | |
rustlings: complete 12
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. } |