From dacdce1ea245523bf7bf380f91bff76e7f867315 Mon Sep 17 00:00:00 2001 From: Yudai Kawabuchi Date: Thu, 1 Aug 2024 09:47:50 +0900 Subject: [PATCH 1/2] fix: update struct name in hashmap3 --- exercises/11_hashmaps/hashmaps3.rs | 4 ++-- solutions/11_hashmaps/hashmaps3.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/exercises/11_hashmaps/hashmaps3.rs b/exercises/11_hashmaps/hashmaps3.rs index 9f8fdd7..7e9584d 100644 --- a/exercises/11_hashmaps/hashmaps3.rs +++ b/exercises/11_hashmaps/hashmaps3.rs @@ -10,12 +10,12 @@ use std::collections::HashMap; // A structure to store the goal details of a team. #[derive(Default)] -struct Team { +struct TeamScores { goals_scored: u8, goals_conceded: u8, } -fn build_scores_table(results: &str) -> HashMap<&str, Team> { +fn build_scores_table(results: &str) -> HashMap<&str, TeamScores> { // The name of the team is the key and its associated struct is the value. let mut scores = HashMap::new(); diff --git a/solutions/11_hashmaps/hashmaps3.rs b/solutions/11_hashmaps/hashmaps3.rs index 54f480b..c075b0f 100644 --- a/solutions/11_hashmaps/hashmaps3.rs +++ b/solutions/11_hashmaps/hashmaps3.rs @@ -10,12 +10,12 @@ use std::collections::HashMap; // A structure to store the goal details of a team. #[derive(Default)] -struct Team { +struct TeamScores { goals_scored: u8, goals_conceded: u8, } -fn build_scores_table(results: &str) -> HashMap<&str, Team> { +fn build_scores_table(results: &str) -> HashMap<&str, TeamScores> { // The name of the team is the key and its associated struct is the value. let mut scores = HashMap::new(); @@ -28,13 +28,13 @@ fn build_scores_table(results: &str) -> HashMap<&str, Team> { let team_2_score: u8 = split_iterator.next().unwrap().parse().unwrap(); // Insert the default with zeros if a team doesn't exist yet. - let team_1 = scores.entry(team_1_name).or_insert_with(Team::default); + let team_1 = scores.entry(team_1_name).or_insert_with(TeamScores::default); // Update the values. team_1.goals_scored += team_1_score; team_1.goals_conceded += team_2_score; // Similarely for the second team. - let team_2 = scores.entry(team_2_name).or_insert_with(Team::default); + let team_2 = scores.entry(team_2_name).or_insert_with(TeamScores::default); team_2.goals_scored += team_2_score; team_2.goals_conceded += team_1_score; } From e65ae09789410c230a863ad219b90c434adf5e4f Mon Sep 17 00:00:00 2001 From: Yudai Kawabuchi Date: Thu, 1 Aug 2024 09:55:25 +0900 Subject: [PATCH 2/2] fix format --- solutions/11_hashmaps/hashmaps3.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/solutions/11_hashmaps/hashmaps3.rs b/solutions/11_hashmaps/hashmaps3.rs index c075b0f..9c58b2d 100644 --- a/solutions/11_hashmaps/hashmaps3.rs +++ b/solutions/11_hashmaps/hashmaps3.rs @@ -28,13 +28,17 @@ fn build_scores_table(results: &str) -> HashMap<&str, TeamScores> { let team_2_score: u8 = split_iterator.next().unwrap().parse().unwrap(); // Insert the default with zeros if a team doesn't exist yet. - let team_1 = scores.entry(team_1_name).or_insert_with(TeamScores::default); + let team_1 = scores + .entry(team_1_name) + .or_insert_with(TeamScores::default); // Update the values. team_1.goals_scored += team_1_score; team_1.goals_conceded += team_2_score; // Similarely for the second team. - let team_2 = scores.entry(team_2_name).or_insert_with(TeamScores::default); + let team_2 = scores + .entry(team_2_name) + .or_insert_with(TeamScores::default); team_2.goals_scored += team_2_score; team_2.goals_conceded += team_1_score; }