This commit is contained in:
palutz 2023-07-23 22:32:09 +01:00
parent ed4e7ae90e
commit f7c3a17cfc
4 changed files with 13 additions and 11 deletions

View File

@ -16,12 +16,15 @@
use std::collections::HashMap; use std::collections::HashMap;
fn fruit_basket() -> HashMap<String, u32> { fn fruit_basket() -> HashMap<String, u32> {
let mut basket = // TODO: declare your hash map here. let mut basket = HashMap::new();// TODO: declare your hash map here.
// Two bananas are already given for you :) // Two bananas are already given for you :)
basket.insert(String::from("banana"), 2); basket.insert(String::from("banana"), 2);
// TODO: Put more fruits in your basket here. // TODO: Put more fruits in your basket here.
basket.insert(String::from("apple"), 1);
basket.insert(String::from("orange"), 3);
basket.insert(String::from("grapes"), 4);
basket basket
} }

View File

@ -3,15 +3,13 @@
// Execute `rustlings hint modules1` or use the `hint` watch subcommand for a // Execute `rustlings hint modules1` or use the `hint` watch subcommand for a
// hint. // hint.
// I AM NOT DONE
mod sausage_factory { mod sausage_factory {
// Don't let anybody outside of this module see this! // Don't let anybody outside of this module see this!
fn get_secret_recipe() -> String { fn get_secret_recipe() -> String {
String::from("Ginger") String::from("Ginger")
} }
fn make_sausage() { pub fn make_sausage() {
get_secret_recipe(); get_secret_recipe();
println!("sausage!"); println!("sausage!");
} }

View File

@ -7,14 +7,13 @@
// Execute `rustlings hint modules2` or use the `hint` watch subcommand for a // Execute `rustlings hint modules2` or use the `hint` watch subcommand for a
// hint. // hint.
// I AM NOT DONE
mod delicious_snacks { mod delicious_snacks {
// TODO: Fix these use statements // TODO: Fix these use statements
use self::fruits::PEAR as ??? pub(crate) use self::fruits::PEAR as fruit;
use self::veggies::CUCUMBER as ??? pub(crate) use self::veggies::CUCUMBER as veggie;
mod fruits { mod fruits {
// I can't remove the pub otherwise these constants won't be visible outside
pub const PEAR: &'static str = "Pear"; pub const PEAR: &'static str = "Pear";
pub const APPLE: &'static str = "Apple"; pub const APPLE: &'static str = "Apple";
} }
@ -26,6 +25,10 @@ mod delicious_snacks {
} }
fn main() { fn main() {
// This won't work --- fruits is a private mod
// println!("let's try to use it this way {}",
// delicious_snacks::fruits::PEAR
// );
println!( println!(
"favorite snacks: {} and {}", "favorite snacks: {} and {}",
delicious_snacks::fruit, delicious_snacks::fruit,

View File

@ -8,10 +8,8 @@
// Execute `rustlings hint modules3` or use the `hint` watch subcommand for a // Execute `rustlings hint modules3` or use the `hint` watch subcommand for a
// hint. // hint.
// I AM NOT DONE
// TODO: Complete this use statement // TODO: Complete this use statement
use ??? use std::time::{SystemTime, UNIX_EPOCH};
fn main() { fn main() {
match SystemTime::now().duration_since(UNIX_EPOCH) { match SystemTime::now().duration_since(UNIX_EPOCH) {