From f146553dead78357cd44736dfca97b1349418fa2 Mon Sep 17 00:00:00 2001 From: mo8it Date: Thu, 17 Oct 2024 14:37:47 +0200 Subject: hashmap3: Use `or_default` --- solutions/11_hashmaps/hashmaps3.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'solutions/11_hashmaps/hashmaps3.rs') diff --git a/solutions/11_hashmaps/hashmaps3.rs b/solutions/11_hashmaps/hashmaps3.rs index 8a5d30b..41da784 100644 --- a/solutions/11_hashmaps/hashmaps3.rs +++ b/solutions/11_hashmaps/hashmaps3.rs @@ -28,17 +28,13 @@ 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_default(); // Update the values. team_1.goals_scored += team_1_score; team_1.goals_conceded += team_2_score; // Similarly 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_default(); team_2.goals_scored += team_2_score; team_2.goals_conceded += team_1_score; } -- cgit v1.2.3