Merge pull request #1 from palutz/steo

modules
This commit is contained in:
S P 2023-07-23 23:03:19 +01:00 committed by GitHub
commit d8d856714e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 11 deletions

View File

@ -16,12 +16,15 @@
use std::collections::HashMap;
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 :)
basket.insert(String::from("banana"), 2);
// 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
}

View File

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

View File

@ -7,14 +7,13 @@
// Execute `rustlings hint modules2` or use the `hint` watch subcommand for a
// hint.
// I AM NOT DONE
mod delicious_snacks {
// TODO: Fix these use statements
use self::fruits::PEAR as ???
use self::veggies::CUCUMBER as ???
pub(crate) use self::fruits::PEAR as fruit;
pub(crate) use self::veggies::CUCUMBER as veggie;
mod fruits {
// I can't remove the pub otherwise these constants won't be visible outside
pub const PEAR: &'static str = "Pear";
pub const APPLE: &'static str = "Apple";
}
@ -26,6 +25,10 @@ mod delicious_snacks {
}
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!(
"favorite snacks: {} and {}",
delicious_snacks::fruit,

View File

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