As Mosicus writes, you can avoid this by calling to_owned.
You can also avoid pushing onto the vector manually:
extern crate walkdir;
use walkdir::*;
fn main() {
let list: Vec<_> = WalkDir::new(".")
.into_iter()
.filter_map(|f| f.ok()) // filter out errors (silently!)
.map(|f| f.path().to_owned()) // take the path and take ownership
.collect(); // collect into whatever list is
}
Vectors can be created from any previous iteration efficiently. Detailed explanations on the chain:
Walkdir#into_iter creates an Iterator from the WalkDir structure
filter_map gives you every element and expects an Option returned. It filters out everything that is None. Result::ok() turns a result into an Option by discarding all errors and making them None.
map applies an operation to every element and gives you the Result
finally, collect() collects all elements into a some collection. This is why we have to annotate list with Vec, because Rust needs to know which type of collection you want. The underscore in Vec<_> tells the compiler to infer the type inside the collection.