summaryrefslogtreecommitdiff
path: root/solutions
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-10-17 14:37:47 +0200
committermo8it <mo8it@proton.me>2024-10-17 14:49:07 +0200
commitf146553dead78357cd44736dfca97b1349418fa2 (patch)
treecc08d5b5f025acb620b755971e37cb1da0b8cf38 /solutions
parent0432e07864d5ee4d2bac1954c965b2077c0447c6 (diff)
hashmap3: Use `or_default`
Diffstat (limited to 'solutions')
-rw-r--r--solutions/11_hashmaps/hashmaps3.rs8
1 files changed, 2 insertions, 6 deletions
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;
}