In the code below, I generate a vector and then use it as content for a closure:
fn main() {
let f = {
let xs: Vec<(usize, usize)> = Vec::new();
// populate xs
move |i, j| xs[j].1 - xs[i].0
};
let x = f(1usize, 2usize);
}
Why this does code fail to compile with a type inference error although the vector is explicitly typed?
error[E0282]: type annotations needed
--> src/main.rs:5:21
|
5 | move |i, j| xs[j].1 - xs[i].0
| ^^^^^ cannot infer type
|
= note: type must be known at this point