Rust .collect()
cannot infer type?
let data = vec![1,2,3].iter().map(|x|x*x).collect();
^^^^ cannot infer type for `_`
The expression is ambiguous, because .collect()
can create not just Vec
, but HashMap
, String
, and others.
Specify the type you want. It's not necessary to type it in full, e.g. Vec<_>
is enough.
let data: = iter.collect;
let data = iter.;
Try it: Rust Playground
PS: Itertools has .collect_vec()
.