Skip to content

Commit 184ee98

Browse files
authored
Rollup merge of #37221 - diwic:6a-readdir-debug, r=alexcrichton
impl Debug for ReadDir It is good practice to implement Debug for public types, and indicating what directory you're reading seems useful. Signed-off-by: David Henningsson <diwic@ubuntu.com>
2 parents eae11c3 + e4ed345 commit 184ee98

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/libstd/fs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ pub struct Metadata(fs_imp::FileAttr);
8383
///
8484
/// [`io::Result`]: ../io/type.Result.html
8585
#[stable(feature = "rust1", since = "1.0.0")]
86+
#[derive(Debug)]
8687
pub struct ReadDir(fs_imp::ReadDir);
8788

8889
/// Entries returned by the [`ReadDir`] iterator.

src/libstd/sys/unix/fs.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ impl FromInner<u32> for FilePermissions {
193193
}
194194
}
195195

196+
impl fmt::Debug for ReadDir {
197+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
198+
// This will only be called from std::fs::ReadDir, which will add a "ReadDir()" frame.
199+
// Thus the result will be e g 'ReadDir("/home")'
200+
fmt::Debug::fmt(&*self.root, f)
201+
}
202+
}
203+
196204
impl Iterator for ReadDir {
197205
type Item = io::Result<DirEntry>;
198206

src/libstd/sys/windows/fs.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ pub struct FilePermissions { attrs: c::DWORD }
8181

8282
pub struct DirBuilder;
8383

84+
impl fmt::Debug for ReadDir {
85+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
86+
// This will only be called from std::fs::ReadDir, which will add a "ReadDir()" frame.
87+
// Thus the result will be e g 'ReadDir("C:\")'
88+
fmt::Debug::fmt(&*self.root, f)
89+
}
90+
}
91+
8492
impl Iterator for ReadDir {
8593
type Item = io::Result<DirEntry>;
8694
fn next(&mut self) -> Option<io::Result<DirEntry>> {

0 commit comments

Comments
 (0)