Skip to content

Commit

Permalink
impl Debug for ReadDir
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
diwic committed Oct 16, 2016
1 parent 6dc035e commit e4ed345
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub struct Metadata(fs_imp::FileAttr);
///
/// [`io::Result`]: ../io/type.Result.html
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Debug)]
pub struct ReadDir(fs_imp::ReadDir);

/// Entries returned by the [`ReadDir`] iterator.
Expand Down
8 changes: 8 additions & 0 deletions src/libstd/sys/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ impl FromInner<u32> for FilePermissions {
}
}

impl fmt::Debug for ReadDir {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// This will only be called from std::fs::ReadDir, which will add a "ReadDir()" frame.
// Thus the result will be e g 'ReadDir("/home")'
fmt::Debug::fmt(&*self.root, f)
}
}

impl Iterator for ReadDir {
type Item = io::Result<DirEntry>;

Expand Down
8 changes: 8 additions & 0 deletions src/libstd/sys/windows/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ pub struct FilePermissions { attrs: c::DWORD }

pub struct DirBuilder;

impl fmt::Debug for ReadDir {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// This will only be called from std::fs::ReadDir, which will add a "ReadDir()" frame.
// Thus the result will be e g 'ReadDir("C:\")'
fmt::Debug::fmt(&*self.root, f)
}
}

impl Iterator for ReadDir {
type Item = io::Result<DirEntry>;
fn next(&mut self) -> Option<io::Result<DirEntry>> {
Expand Down

0 comments on commit e4ed345

Please sign in to comment.