rust-lang / rfcs

RFCs for changes to Rust
https://rust-lang.github.io/rfcs/
Apache License 2.0
5.9k stars 1.56k forks source link

Create a struct similar to std::fs::File for directories #3644

Closed MarkusTieger closed 4 months ago

MarkusTieger commented 4 months ago

There is currently no safe way in rust to open a filedescriptor on a directory and using it for reading entries. Currently you always have to open a new filedescriptor using std::fs::read_dir<P: AsRef<Path>>(path: P) -> io::Result<ReadDir>. At least for my understanding, if you need to access the directory multiple times (for example for a directory watcher), this is inefficient.

A solution would be to introduce a new struct called "Dir" or "Directory" with a "read_dir" function, which can be used to access a directory multiple times without opening another filedescriptor. Another solution would be to extend the std::fs::File struct with a "read_dir" function.

BurntSushi commented 4 months ago

https://github.com/rust-lang/rust/issues/120426

MarkusTieger commented 4 months ago

Sorry for the duplicate