Understanding fs::walk_dir alternative



As many others, with beta, I’m trying rust with a small program. In this program I want to walk a directory tree.

Because std::fs::walk_dir is currently unstable I’m looking for other solution.

The std::fs::read_dir documentation suggest a possible implementation of fs::walk_dir but don’t show how to call it.

The signature is visit_dirs(dir: &Path, cb: &mut FnMut(DirEntry)) -> io::Result<()> and this is the cb: &mut FnMut(DirEntry) that I don’t grasp.

Thanks for your help.


Ok, so it seems I haven’t read enough of the book and the cb parameter is a closure … anyway this function use unstable feature path_ext.

So finally any idea to implement a directory tree walk with beta ?


Replying to myself. Sorry for the newbie question. FnMut in the function signature trouble me. Of course it is possible to call recursively fs::read_dir to walk a directory.

Here it is a example, I’ve not really manage errors and put unwrap everywhere, but beyond this is it correct rust ?


Thank for feedback.