fn main() {
let a = ["1", "2", "lol"];
let cnt = a.iter().filter_map(|s| s.parse().ok()).count();
}
錯誤消息如何爲Iterator :: filter_map指定類型信息?
<anon>:3:24: 3:34 error: unable to infer enough type information about `_`; type annotations or generic parameter binding required [E0282]
<anon>:3 let cnt = a.iter().filter_map(|s| s.parse().ok()).count();
^~~~~~~~~~
我試圖爲filter_map()
指定類型,但沒有成功。如果可能的話,我也想知道爲什麼如果我刪除了count()
方法,編譯器不會抱怨。
刪除'.count()'有同樣的錯誤,[據我所見](https://play.rust-lang.org/?gist=5a204c4e748c6cb5138533947591e0cd&version=穩定的回溯= 0)。 – Shepmaster