From 2844976587f698868ea00baf7dc9210d05f0aa23 Mon Sep 17 00:00:00 2001 From: AramJonghu Date: Sun, 26 Jul 2026 02:05:57 +0200 Subject: [PATCH] progress(modules + hashmaps): finished modules and almost done hashmaps --- "\\" | 49 ------------------------------ exercises/10_modules/modules1.rs | 2 +- exercises/10_modules/modules2.rs | 3 ++ exercises/10_modules/modules3.rs | 2 ++ exercises/11_hashmaps/hashmaps1.rs | 5 +-- exercises/11_hashmaps/hashmaps2.rs | 4 ++- 6 files changed, 12 insertions(+), 53 deletions(-) delete mode 100644 "\\" diff --git "a/\\" "b/\\" deleted file mode 100644 index a732145..0000000 --- "a/\\" +++ /dev/null @@ -1,49 +0,0 @@ -#[derive(Debug)] -struct Order { - name: String, - year: u32, - made_by_phone: bool, - made_by_mobile: bool, - made_by_email: bool, - item_number: u32, - count: u32, -} - -fn create_order_template() -> Order { - Order { - name: String::from("Bob"), - year: 2019, - made_by_phone: false, - made_by_mobile: false, - made_by_email: true, - item_number: 123, - count: 0, - } -} - -fn main() { - // You can optionally experiment here. -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn your_order() { - let order_template = create_order_template(); - - // TODO: Create your own order using the update syntax and template above! - // let your_order = - - let your_order = ; - - assert_eq!(your_order.name, "Hacker in Rust"); - assert_eq!(your_order.year, order_template.year); - assert_eq!(your_order.made_by_phone, order_template.made_by_phone); - assert_eq!(your_order.made_by_mobile, order_template.made_by_mobile); - assert_eq!(your_order.made_by_email, order_template.made_by_email); - assert_eq!(your_order.item_number, order_template.item_number); - assert_eq!(your_order.count, 1); - } -} diff --git a/exercises/10_modules/modules1.rs b/exercises/10_modules/modules1.rs index d97ab23..81981df 100644 --- a/exercises/10_modules/modules1.rs +++ b/exercises/10_modules/modules1.rs @@ -5,7 +5,7 @@ mod sausage_factory { String::from("Ginger") } - fn make_sausage() { + pub fn make_sausage() { get_secret_recipe(); println!("sausage!"); } diff --git a/exercises/10_modules/modules2.rs b/exercises/10_modules/modules2.rs index 782a70e..dbb44fc 100644 --- a/exercises/10_modules/modules2.rs +++ b/exercises/10_modules/modules2.rs @@ -5,6 +5,9 @@ mod delicious_snacks { // TODO: Add the following two `use` statements after fixing them. // use self::fruits::PEAR as ???; // use self::veggies::CUCUMBER as ???; + + pub use self::fruits::PEAR as fruit; + pub use self::veggies::CUCUMBER as veggie; mod fruits { pub const PEAR: &str = "Pear"; diff --git a/exercises/10_modules/modules3.rs b/exercises/10_modules/modules3.rs index 691608d..d2ba71c 100644 --- a/exercises/10_modules/modules3.rs +++ b/exercises/10_modules/modules3.rs @@ -4,6 +4,8 @@ // TODO: Bring `SystemTime` and `UNIX_EPOCH` from the `std::time` module into // your scope. Bonus style points if you can do it with one line! // use ???; +use std::time::SystemTime; +use std::time::UNIX_EPOCH; fn main() { match SystemTime::now().duration_since(UNIX_EPOCH) { diff --git a/exercises/11_hashmaps/hashmaps1.rs b/exercises/11_hashmaps/hashmaps1.rs index 74001d0..2ad0581 100644 --- a/exercises/11_hashmaps/hashmaps1.rs +++ b/exercises/11_hashmaps/hashmaps1.rs @@ -9,10 +9,11 @@ use std::collections::HashMap; fn fruit_basket() -> HashMap { // TODO: Declare the hash map. // let mut basket = - + let mut basket = HashMap::new(); // Two bananas are already given for you :) basket.insert(String::from("banana"), 2); - + basket.insert(String::from("apple"), 2); + basket.insert(String::from("mango"), 1); // TODO: Put more fruits in your basket. basket diff --git a/exercises/11_hashmaps/hashmaps2.rs b/exercises/11_hashmaps/hashmaps2.rs index e9f53fe..525482f 100644 --- a/exercises/11_hashmaps/hashmaps2.rs +++ b/exercises/11_hashmaps/hashmaps2.rs @@ -28,10 +28,12 @@ fn fruit_basket(basket: &mut HashMap) { Fruit::Pineapple, ]; - for fruit in fruit_kinds { + for _fruit in fruit_kinds { // TODO: Insert new fruits if they are not already present in the // basket. Note that you are not allowed to put any type of fruit that's // already present! + basket.insert(Fruit::Banana, 4); + basket.insert(Fruit::Pineapple, 3); } }