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/exercises/12_options/README.md | 21 --------------- rustlings/exercises/12_options/options1.rs | 42 ------------------------------ rustlings/exercises/12_options/options2.rs | 39 --------------------------- rustlings/exercises/12_options/options3.rs | 17 ------------ 4 files changed, 119 deletions(-) delete mode 100644 rustlings/exercises/12_options/README.md delete mode 100644 rustlings/exercises/12_options/options1.rs delete mode 100644 rustlings/exercises/12_options/options2.rs delete mode 100644 rustlings/exercises/12_options/options3.rs (limited to 'rustlings/exercises/12_options') diff --git a/rustlings/exercises/12_options/README.md b/rustlings/exercises/12_options/README.md deleted file mode 100644 index 624572a..0000000 --- a/rustlings/exercises/12_options/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# Options - -Type Option represents an optional value: every Option is either Some and contains a value, or None, and does not. -Option types are very common in Rust code, as they have a number of uses: - -- Initial values -- Return values for functions that are not defined over their entire input range (partial functions) -- Return value for otherwise reporting simple errors, where None is returned on error -- Optional struct fields -- Struct fields that can be loaned or "taken" -- Optional function arguments -- Nullable pointers -- Swapping things out of difficult situations - -## Further Information - -- [Option Enum Format](https://doc.rust-lang.org/book/ch10-01-syntax.html#in-enum-definitions) -- [Option Module Documentation](https://doc.rust-lang.org/std/option/) -- [Option Enum Documentation](https://doc.rust-lang.org/std/option/enum.Option.html) -- [if let](https://doc.rust-lang.org/rust-by-example/flow_control/if_let.html) -- [while let](https://doc.rust-lang.org/rust-by-example/flow_control/while_let.html) diff --git a/rustlings/exercises/12_options/options1.rs b/rustlings/exercises/12_options/options1.rs deleted file mode 100644 index be97952..0000000 --- a/rustlings/exercises/12_options/options1.rs +++ /dev/null @@ -1,42 +0,0 @@ -// This function returns how much ice cream 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 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 { - if hour_of_day >= 24 { - return None; - } - if hour_of_day >= 22 { - return Some(0); - } - Some(5) -} - -fn main() { - // You can optionally experiment here. -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn raw_value() { - // TODO: Fix this test. How do you get the value contained in the - // Option? - let ice_creams = maybe_ice_cream(12).unwrap(); - - assert_eq!(ice_creams, 5); // Don't change this line. - } - - #[test] - fn check_ice_cream() { - assert_eq!(maybe_ice_cream(0), Some(5)); - assert_eq!(maybe_ice_cream(9), Some(5)); - assert_eq!(maybe_ice_cream(18), Some(5)); - assert_eq!(maybe_ice_cream(22), Some(0)); - assert_eq!(maybe_ice_cream(23), Some(0)); - assert_eq!(maybe_ice_cream(24), None); - assert_eq!(maybe_ice_cream(25), None); - } -} diff --git a/rustlings/exercises/12_options/options2.rs b/rustlings/exercises/12_options/options2.rs deleted file mode 100644 index 1039d61..0000000 --- a/rustlings/exercises/12_options/options2.rs +++ /dev/null @@ -1,39 +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); - - // TODO: Make this an if-let statement whose value is `Some`. - 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; - - // TODO: Make this a while-let statement. Remember that `Vec::pop()` - // adds another layer of `Option`. You can do nested pattern matching - // in if-let and while-let statements. - while let Some(Some(integer)) = optional_integers.pop() { - assert_eq!(integer, cursor); - cursor -= 1; - } - - assert_eq!(cursor, 0); - } -} diff --git a/rustlings/exercises/12_options/options3.rs b/rustlings/exercises/12_options/options3.rs deleted file mode 100644 index aecb7a5..0000000 --- a/rustlings/exercises/12_options/options3.rs +++ /dev/null @@ -1,17 +0,0 @@ -#[derive(Debug)] -struct Point { - x: i32, - y: i32, -} - -fn main() { - let optional_point = Some(Point { x: 100, y: 200 }); - - // TODO: Fix the compiler error by adding something to this match statement. - match optional_point { - Some(ref p) => println!("Coordinates are {},{}", p.x, p.y), - _ => panic!("No match!"), - } - - println!("{optional_point:?}"); // Don't change this line. -} -- cgit v1.2.3