BurntSushi / walkdir

Rust library for walking directories recursively.
The Unlicense
1.21k stars 106 forks source link

api: add `From<DirEntry>` implementation for PathBuf #149

Closed Legorooj closed 3 years ago

Legorooj commented 3 years ago

Adds support for PathBuf::from(DirEntry) and DirEntry::into() for PathBuf.

BurntSushi commented 3 years ago

Could you say why you want this?

Legorooj commented 3 years ago

To save doing manual conversions for functions - a large number of functions in the Rust ecosystem (including stdlib) use Into, From, and AsRef as trait bounds on function calls. Adding this allows for things like fs::File::open(DirEntry) and others, which accept generics such as AsRef<Path> or Into<PathBuf>.

thingy.into() is also a very common pattern for type conversions, so having it available is nice.

BurntSushi commented 3 years ago

Thanks for explaining. Unfortunately, I don't think they are a good fit. A DirEntry is more than just a path, so I think implementing these traits in a way that automatically drops all other information in a DirEntry is not such a good idea. I think reasonable people can disagree on this point.