type annotations needed error on collect into HashMap
rustc 1.78. I'm grouping a vec of records by a key:
let grouped = records.into_iter().fold(HashMap::new(), |mut acc, r| {
acc.entry(r.kind).or_default().push(r);
acc
});
Compiler says:
error[E0282]: type annotations needed
--> src/group.rs:21:18
|
21 | let grouped = records.into_iter().fold(HashMap::new(), |mut acc, r| {
| ^^^^^^^ consider giving grouped a type
I know the key is an enum and the value should be Vec<Record>. Why can't it infer that from the entry call?
4 replies