From 4dfc11d74ab02ac5765ae5d08fb750c91f4744b4 Mon Sep 17 00:00:00 2001 From: Hunter Kvalevog Date: Fri, 2 Oct 2026 21:53:51 -0500 Subject: rustlings: move to rust/ --- rustlings/solutions/12_options/options1.rs | 39 ------------------------------ rustlings/solutions/12_options/options2.rs | 37 ---------------------------- rustlings/solutions/12_options/options3.rs | 27 --------------------- 3 files changed, 103 deletions(-) delete mode 100644 rustlings/solutions/12_options/options1.rs delete mode 100644 rustlings/solutions/12_options/options2.rs delete mode 100644 rustlings/solutions/12_options/options3.rs (limited to 'rustlings/solutions/12_options') diff --git a/rustlings/solutions/12_options/options1.rs b/rustlings/solutions/12_options/options1.rs deleted file mode 100644 index 4d615dd..0000000 --- a/rustlings/solutions/12_options/options1.rs +++ /dev/null @@ -1,39 +0,0 @@ -// This function returns how much icecream there is left in the fridge. -// If it's before 22:00 (24-hour system), then 5 scoops are left. At 22:00, -// someone eats it all, so no icecream is left (value 0). Return `None` if -// `hour_of_day` is higher than 23. -fn maybe_icecream(hour_of_day: u16) -> Option { - match hour_of_day { - 0..=21 => Some(5), - 22..=23 => Some(0), - _ => None, - } -} - -fn main() { - // You can optionally experiment here. -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn raw_value() { - // Using `unwrap` is fine in a test. - let icecreams = maybe_icecream(12).unwrap(); - - assert_eq!(icecreams, 5); - } - - #[test] - fn check_icecream() { - assert_eq!(maybe_icecream(0), Some(5)); - assert_eq!(maybe_icecream(9), Some(5)); - assert_eq!(maybe_icecream(18), Some(5)); - assert_eq!(maybe_icecream(22), Some(0)); - assert_eq!(maybe_icecream(23), Some(0)); - assert_eq!(maybe_icecream(24), None); - assert_eq!(maybe_icecream(25), None); - } -} diff --git a/rustlings/solutions/12_options/options2.rs b/rustlings/solutions/12_options/options2.rs deleted file mode 100644 index 0f24665..0000000 --- a/rustlings/solutions/12_options/options2.rs +++ /dev/null @@ -1,37 +0,0 @@ -fn main() { - // You can optionally experiment here. -} - -#[cfg(test)] -mod tests { - #[test] - fn simple_option() { - let target = "rustlings"; - let optional_target = Some(target); - - // if-let - if let Some(word) = optional_target { - assert_eq!(word, target); - } - } - - #[test] - fn layered_option() { - let range = 10; - let mut optional_integers: Vec> = vec![None]; - - for i in 1..=range { - optional_integers.push(Some(i)); - } - - let mut cursor = range; - - // while-let with nested pattern matching - while let Some(Some(integer)) = optional_integers.pop() { - assert_eq!(integer, cursor); - cursor -= 1; - } - - assert_eq!(cursor, 0); - } -} diff --git a/rustlings/solutions/12_options/options3.rs b/rustlings/solutions/12_options/options3.rs deleted file mode 100644 index c918f71..0000000 --- a/rustlings/solutions/12_options/options3.rs +++ /dev/null @@ -1,27 +0,0 @@ -#[derive(Debug)] -struct Point { - x: i32, - y: i32, -} - -fn main() { - let optional_point = Some(Point { x: 100, y: 200 }); - - // Solution 1: Matching over the `Option` (not `&Option`) but without moving - // out of the `Some` variant. - match optional_point { - Some(ref p) => println!("Coordinates are {},{}", p.x, p.y), - // ^^^ added - _ => panic!("No match!"), - } - - // Solution 2: Matching over a reference (`&Option`) by added `&` before - // `optional_point`. - match &optional_point { - //^ added - Some(p) => println!("Coordinates are {},{}", p.x, p.y), - _ => panic!("No match!"), - } - - println!("{optional_point:?}"); -} -- cgit v1.2.3