File tree Expand file tree Collapse file tree 2 files changed +4
-12
lines changed Expand file tree Collapse file tree 2 files changed +4
-12
lines changed Original file line number Diff line number Diff line change @@ -575,12 +575,8 @@ https://doc.rust-lang.org/book/ch08-03-hash-maps.html#only-inserting-a-value-if-
575575name = " hashmaps3"
576576dir = " 11_hashmaps"
577577hint = """
578- Hint 1: Use the `entry()` and `or_insert()` (or `or_insert_with()`) methods of
579- `HashMap` to insert the default value of `TeamScores` if a team doesn't
580- exist in the table yet.
581-
582- Learn more in The Book:
583- https://doc.rust-lang.org/book/ch08-03-hash-maps.html#only-inserting-a-value-if-the-key-has-no-value
578+ Hint 1: Use the `entry()` and `or_default()` methods of `HashMap` to insert the
579+ default value of `TeamScores` if a team doesn't exist in the table yet.
584580
585581Hint 2: If there is already an entry for a given key, the value returned by
586582 `entry()` can be updated based on the existing value.
Original file line number Diff line number Diff line change @@ -28,17 +28,13 @@ fn build_scores_table(results: &str) -> HashMap<&str, TeamScores> {
2828 let team_2_score: u8 = split_iterator. next ( ) . unwrap ( ) . parse ( ) . unwrap ( ) ;
2929
3030 // Insert the default with zeros if a team doesn't exist yet.
31- let team_1 = scores
32- . entry ( team_1_name)
33- . or_insert_with ( TeamScores :: default) ;
31+ let team_1 = scores. entry ( team_1_name) . or_default ( ) ;
3432 // Update the values.
3533 team_1. goals_scored += team_1_score;
3634 team_1. goals_conceded += team_2_score;
3735
3836 // Similarly for the second team.
39- let team_2 = scores
40- . entry ( team_2_name)
41- . or_insert_with ( TeamScores :: default) ;
37+ let team_2 = scores. entry ( team_2_name) . or_default ( ) ;
4238 team_2. goals_scored += team_2_score;
4339 team_2. goals_conceded += team_1_score;
4440 }
You can’t perform that action at this time.
0 commit comments