This commit is contained in:
jiangker 2024-07-10 15:08:34 +08:00
parent 512d418f7f
commit deadba31d5
7 changed files with 30 additions and 14 deletions

View File

@ -5,7 +5,7 @@ mod sausage_factory {
String::from("Ginger")
}
fn make_sausage() {
pub fn make_sausage() {
get_secret_recipe();
println!("sausage!");
}

View File

@ -4,8 +4,8 @@
#[allow(dead_code)]
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";

View File

@ -3,7 +3,7 @@
// 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, UNIX_EPOCH};
fn main() {
match SystemTime::now().duration_since(UNIX_EPOCH) {

View File

@ -8,12 +8,14 @@ use std::collections::HashMap;
fn fruit_basket() -> HashMap<String, u32> {
// 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);
// TODO: Put more fruits in your basket.
basket.insert(String::from("apple"), 3);
basket.insert(String::from("watermelon"), 1);
basket
}

View File

@ -29,9 +29,7 @@ fn fruit_basket(basket: &mut HashMap<Fruit, u32>) {
];
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.entry(fruit).or_insert(1);
}
}

View File

@ -27,10 +27,12 @@ fn build_scores_table(results: &str) -> HashMap<&str, Team> {
let team_1_score: u8 = split_iterator.next().unwrap().parse().unwrap();
let team_2_score: u8 = split_iterator.next().unwrap().parse().unwrap();
// TODO: Populate the scores table with the extracted details.
// Keep in mind that goals scored by team 1 will be the number of goals
// conceded by team 2. Similarly, goals scored by team 2 will be the
// number of goals conceded by team 1.
let entry1 = scores.entry(team_1_name).or_insert(Team { goals_scored: 0, goals_conceded: 0 });
entry1.goals_scored += team_1_score;
entry1.goals_conceded += team_2_score;
let entry2 = scores.entry(team_2_name).or_insert(Team { goals_scored: 0, goals_conceded: 0 });
entry2.goals_scored += team_2_score;
entry2.goals_conceded += team_1_score;
}
scores

View File

@ -27,7 +27,21 @@ mod my_module {
use super::Command;
// TODO: Complete the function.
// pub fn transformer(input: ???) -> ??? { ??? }
pub fn transformer(input: Vec<(String, Command)>) -> Vec<String> {
input.iter().map(|(item, cmd)| {
match cmd {
Command::Uppercase => {
item.to_uppercase()
}
Command::Trim => {
item.trim().to_string()
}
Command::Append(size) => {
format!("{}{}", item, "bar".repeat(*size))
}
}
}).collect()
}
}
fn main() {
@ -37,7 +51,7 @@ fn main() {
#[cfg(test)]
mod tests {
// TODO: What do we need to import to have `transformer` in scope?
// use ???;
use super::my_module::{transformer};
use super::Command;
#[test]