about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorEduard-Mihai Burtescu <edy.burt@gmail.com>2016-10-19 08:00:02 +0300
committerGitHub <noreply@github.com>2016-10-19 08:00:02 +0300
commit184ee985f846dfea0275412a794c17a455148307 (patch)
tree5544f913a0a8a2b4c2f0111578933ad3c8ad4660 /src/libstd
parenteae11c35c9f5b7af48fd5d45e221f5f40fc4fd60 (diff)
parente4ed345b2ca84db1b3300661aa3940afc0c0cbf0 (diff)
downloadrust-184ee985f846dfea0275412a794c17a455148307.tar.gz
rust-184ee985f846dfea0275412a794c17a455148307.zip
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>
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/fs.rs1
-rw-r--r--src/libstd/sys/unix/fs.rs8
-rw-r--r--src/libstd/sys/windows/fs.rs8
3 files changed, 17 insertions, 0 deletions
diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs
index 5bb5183fd6a..df5741d00a2 100644
--- a/src/libstd/fs.rs
+++ b/src/libstd/fs.rs
@@ -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.
diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs
index fe8cbc84215..b77008676b1 100644
--- a/src/libstd/sys/unix/fs.rs
+++ b/src/libstd/sys/unix/fs.rs
@@ -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>;
 
diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs
index a927eae020d..98fd15f863b 100644
--- a/src/libstd/sys/windows/fs.rs
+++ b/src/libstd/sys/windows/fs.rs
@@ -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>> {