File system iteration and filtering is complicated
We use the walkdir
crate to iterate over the file system, but we hide it behind our own abstraction, FsIter
. We then add some filtering support filtering cache directories. The result is a bit complicated and the logic of how filtering decisions are made is a little hard to follow, at least for me.
I think a tidier approach would be to drop FsIter
and use walkdir
directly, and use its FilterEntry
to do the filtering. This way, the caller sees a more common iterator in use. Something like:
for entry in WalkDir::new(&root)
.into_iter()
.filter_entry(|e| !unwanted(e))
{
let entry = entry?;
println!("{}", entry.path().display());
}
fn unwanted(e: &DirEntry) -> bool {
e.file_name() == ".git"
}
Opinions?