Going through rustlings for the first time

ex(10): modules

+49 -9
+5 -2
.rustlings-state.txt
··· 1 1 DON'T EDIT THIS FILE! 2 2 3 - modules1 3 + hashmaps1 4 4 5 5 intro1 6 6 intro2 ··· 41 41 strings1 42 42 strings2 43 43 strings3 44 - strings4 44 + strings4 45 + modules1 46 + modules2 47 + modules3
+1 -1
exercises/10_modules/modules1.rs
··· 5 5 String::from("Ginger") 6 6 } 7 7 8 - fn make_sausage() { 8 + pub fn make_sausage() { 9 9 get_secret_recipe(); 10 10 println!("sausage!"); 11 11 }
+2
exercises/10_modules/modules2.rs
··· 5 5 // TODO: Add the following two `use` statements after fixing them. 6 6 // use self::fruits::PEAR as ???; 7 7 // use self::veggies::CUCUMBER as ???; 8 + pub use self::fruits::PEAR as fruit; 9 + pub use self::veggies::CUCUMBER as veggie; 8 10 9 11 mod fruits { 10 12 pub const PEAR: &str = "Pear";
+1
exercises/10_modules/modules3.rs
··· 4 4 // TODO: Bring `SystemTime` and `UNIX_EPOCH` from the `std::time` module into 5 5 // your scope. Bonus style points if you can do it with one line! 6 6 // use ???; 7 + use std::time::{SystemTime, UNIX_EPOCH}; 7 8 8 9 fn main() { 9 10 match SystemTime::now().duration_since(UNIX_EPOCH) {
+13 -2
solutions/10_modules/modules1.rs
··· 1 + mod sausage_factory { 2 + fn get_secret_recipe() -> String { 3 + String::from("Ginger") 4 + } 5 + 6 + // Added `pub` before `fn` to make the function accessible outside the module. 7 + pub fn make_sausage() { 8 + get_secret_recipe(); 9 + println!("sausage!"); 10 + } 11 + } 12 + 1 13 fn main() { 2 - // DON'T EDIT THIS SOLUTION FILE! 3 - // It will be automatically filled after you finish the exercise. 14 + sausage_factory::make_sausage(); 4 15 }
+21 -2
solutions/10_modules/modules2.rs
··· 1 + mod delicious_snacks { 2 + // Added `pub` and used the expected alias after `as`. 3 + pub use self::fruits::PEAR as fruit; 4 + pub use self::veggies::CUCUMBER as veggie; 5 + 6 + mod fruits { 7 + pub const PEAR: &str = "Pear"; 8 + pub const APPLE: &str = "Apple"; 9 + } 10 + 11 + mod veggies { 12 + pub const CUCUMBER: &str = "Cucumber"; 13 + pub const CARROT: &str = "Carrot"; 14 + } 15 + } 16 + 1 17 fn main() { 2 - // DON'T EDIT THIS SOLUTION FILE! 3 - // It will be automatically filled after you finish the exercise. 18 + println!( 19 + "favorite snacks: {} and {}", 20 + delicious_snacks::fruit, 21 + delicious_snacks::veggie, 22 + ); 4 23 }
+6 -2
solutions/10_modules/modules3.rs
··· 1 + use std::time::{SystemTime, UNIX_EPOCH}; 2 + 1 3 fn main() { 2 - // DON'T EDIT THIS SOLUTION FILE! 3 - // It will be automatically filled after you finish the exercise. 4 + match SystemTime::now().duration_since(UNIX_EPOCH) { 5 + Ok(n) => println!("1970-01-01 00:00:00 UTC was {} seconds ago!", n.as_secs()), 6 + Err(_) => panic!("SystemTime before UNIX EPOCH!"), 7 + } 4 8 }