I'm learning rust using rustlings. I was trying to implement a solution in a functional way (rustlings only asked for the imperative way). I'm running into the following compiler error and haven't been able to figure this out since 2 hours. Please help
Compiler error:
Progress: [############################>-------------------------------] 45/94
! Compiling of exercises/hashmaps/hashmaps3.rs failed! Please try again. Here's the output:
error[E0308]: mismatched types
--> exercises/hashmaps/hashmaps3.rs:94:28
|
94 | .and_modify(|team| Team {
| ____________________________^
95 | | name: team.name.to_string(),
96 | | goals_scored: team.goals_scored+team_from_iter.goals_scored,
97 | | goals_conceded: team.goals_conceded+team_from_iter.goals_conceded,
98 | | })
| |_________^ expected `()`, found struct `Team`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
Code
This is the set of lines the compiler has an issue with
.and_modify(|team| Team {
name: team.name.to_string(),
goals_scored: team.goals_scored+team_from_iter.goals_scored,
goals_conceded: team.goals_conceded+team_from_iter.goals_conceded,
})
Link to full code repo:
- To the exact lines with the issue: https://github.com/dheerajbhaskar/learn-rust-rustlings-PUBLIC/blob/a3d38c643fc178f05a847e7cb8016a784b0a54ac/exercises/hashmaps/hashmaps3.rs#L94-L98
- To the repo: https://github.com/dheerajbhaskar/learn-rust-rustlings-PUBLIC
Additional information
- I've written very similar code on line 119 which compiles and passes the tests. I've not been able to understand why that worked but code at line 94 above didn't. Edit: looks like I've compiler error both these lines now ¯\_(ツ)_/¯
- I'm a rust noob if it wasn't apparent yet :)