I want to read all the files in the current directory.
Here's my progress:
use std::fs;
fn main() {
let files = fs::read_dir(".").unwrap();
files
.filter_map(Result::ok)
.filter(|d| if let Some(e) = d.path().extension() { e == "txt" } else {false})
.for_each(|f| println!("{:?}", f));
}
Here I got a little lost, how can I read all file contents? Should I add them to a growing Vec
in the for_each
block? if so then how?