In fact, your problem was somewhat less noticeable. This does not compile (your source code snippet):
fn load_file() -> Vec<String> {
let path = Path::new("foo.txt");
let mut file = BufferedReader::new(File::open(&path));
file.lines().map(|x| x.unwrap()).collect();
}
fn main() {
let data = load_file();
println!("DATA: {}", data[0]);
}
But it does:
fn load_file() -> Vec<String> {
let path = Path::new("foo.txt");
let mut file = BufferedReader::new(File::open(&path));
file.lines().map(|x| x.unwrap()).collect()
}
fn main() {
let data = load_file();
println!("DATA: {}", data[0]);
}
Can you notice the subtle difference? (this is just a semicolon in the last line load_file())
Rust , . , collect()! "" , collect() load_file() . ; , , ( , () Vec<String>).