Hello!
Googling I found this example:
use std::io;
use std::fs::{self, DirEntry};
use std::path::Path;
// one possible implementation of walking a directory only visiting files
fn visit_dirs(dir: &Path, cb: &dyn Fn(&DirEntry)) -> io::Result<()> {
if dir.is_dir() {
for entry in fs::read_dir(dir)? {
let entry = entry?;
let path = entry.path();
if path.is_dir() {
visit_dirs(&path, cb)?;
} else {
cb(&entry);
}
}
}
Ok(())
}
But I cannot figure out how to use it - what is "cb"? I have never seen the "&dyn Fn.." syntax before ( new user). And how would I alter the function so that it would keep error checking but actually also output a vector of the files in the directory?
Kind regards