This works:
let paths: Vec<String> = args.collect();
let paths = paths.iter().map(|f| std::path::Path::new(&f));
This doesn't work:
let paths = ::std::env::args().map(|f| std::path::Path::new(&f));
error[E0597]: `f` does not live long enough
--> src/main.rs:2:66
|
2 | let paths = ::std::env::args().map(|f| std::path::Path::new(&f));
| ^-- borrowed value needs to live until here
| ||
| |`f` dropped here while still borrowed
| borrowed value does not live long enough
Why do I need to collect
the args
iterator into a vector just to produce another iterator? Why can't I produce one iterator directly from another?