Let's look up the signature of filter_map to see, what the complain is about:
fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F> where F: FnMut(Self::Item) -> Option<B>,
Okay, so Option<B>
is the result, which means he cannot infer what w.parse().ok()
will be.
Let's try to give him a hint
.filter_map(|w| w.parse::<i32>().ok())
Let's compile an see.... Hurray!
So, lesson learned: Look up the signature and try to figure out, which part the compiler cannot infer and try to specify it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…