Skip to content

Commit e4ed345

Browse files
committed
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 <[email protected]>
1 parent 6dc035e commit e4ed345

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/libstd/fs.rs

+1
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

+8
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

+8
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)