Closed dev-ardi closed 9 months ago
I'm not sure this is really something I want to add.
First, I'm skeptical that it is one of the most common use cases. I've used walkdir
a fair bit myself, and I don't think I've ever written that code.
Second, it silently drops errors. (This is probably one of the reasons why I've never written something like what you've provided.)
Third, I don't use impl Trait
in public APIs unless there is no other choice. So this would need to return a new named iterator type. Not a deal breaker, but it's more of an API addition than just a simple method.
You could address the second concern by returning a Item = Result<walkdir::DirEntry, walkdir::Error>
, but then the helper routine just turns into a pretty trivial filter
function. I'm generally happy for callers to need to write that themselves.
I think I'm just going to say no to do this. Thank you for the suggestion though.
That's fair, it's just a pattern that I've used a bunch of times for quick scripts, thanks for answering.
Third, I don't use impl Trait in public APIs unless there is no other choice.
Why is this?
Probably one of the most common use cases for walkdir is to recursively get a list of files given a folder. Why not add something like
So that a user can just do
let files = walkdir::WalkDir::new("my/folder").files();
?