Given this:
let v = vec!("1", "2", "3");
Why does this work:
let v2 : Vec<Result<u32,ParseIntError>> = v.iter().map( |s| s.parse() ).collect();
But this fails:
let v2 : Vec<Result<u32,ParseIntError>> = v.iter().map(str::parse).collect();
error[E0631]: type mismatch in function arguments
--> main.rs:5:58
|
5 | ...().map(str::parse).collect();
| ^^^^^^^^^^
| |
| expected signature of `fn(&&str) -> _`
| found signature of `for<'r> fn(&'r str) -> _`
I thought those two were roughly equivalent, but there's clearly a difference, and I'm trying to better understand that difference. ;). Now, because the strings are literal, that means they're &str
to begin with and by using iter
, I believe they get borrowed again, so I guess I see why it's expecting &&str
... but why doesn't the closure version get the same error?