Skip to content

Commit 032358b

Browse files
authored
Rollup merge of #95962 - sourcefrog:doc-direntry, r=Dylan-DPC
Document that DirEntry holds the directory open I had a bug where holding onto DirEntry structs caused file descriptor exhaustion, and thought it would be good to document this.
2 parents d449a63 + 7cdef08 commit 032358b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

library/std/src/fs.rs

+10
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ pub struct ReadDir(fs_imp::ReadDir);
132132
/// An instance of `DirEntry` represents an entry inside of a directory on the
133133
/// filesystem. Each entry can be inspected via methods to learn about the full
134134
/// path or possibly other metadata through per-platform extension traits.
135+
///
136+
/// # Platform-specific behavior
137+
///
138+
/// On Unix, the `DirEntry` struct contains an internal reference to the open
139+
/// directory. Holding `DirEntry` objects will consume a file handle even
140+
/// after the `ReadDir` iterator is dropped.
141+
///
142+
/// Note that this [may change in the future][changes].
143+
///
144+
/// [changes]: io#platform-specific-behavior
135145
#[stable(feature = "rust1", since = "1.0.0")]
136146
pub struct DirEntry(fs_imp::DirEntry);
137147

0 commit comments

Comments
 (0)