]> git.lizzy.rs Git - rust.git/commitdiff
Implement Debug for DirEntry.
authorCorey Farwell <coreyf@rwell.org>
Wed, 21 Sep 2016 18:57:04 +0000 (14:57 -0400)
committerCorey Farwell <coreyf@rwell.org>
Thu, 22 Sep 2016 18:08:03 +0000 (14:08 -0400)
src/libstd/fs.rs

index 698ec4f1b7389cbc3cabddb22b34a14001400d69..576198564dbd43f7393335460a51c07d06c74195 100644 (file)
@@ -1055,6 +1055,15 @@ pub fn file_name(&self) -> OsString {
     }
 }
 
+#[stable(feature = "dir_entry_debug", since = "1.13.0")]
+impl fmt::Debug for DirEntry {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        f.debug_tuple("DirEntry")
+            .field(&self.path())
+            .finish()
+    }
+}
+
 impl AsInner<fs_imp::DirEntry> for DirEntry {
     fn as_inner(&self) -> &fs_imp::DirEntry { &self.0 }
 }
@@ -2641,6 +2650,17 @@ fn dir_entry_methods() {
         }
     }
 
+    #[test]
+    fn dir_entry_debug() {
+        let tmpdir = tmpdir();
+        File::create(&tmpdir.join("b")).unwrap();
+        let mut read_dir = tmpdir.path().read_dir().unwrap();
+        let dir_entry = read_dir.next().unwrap().unwrap();
+        let actual = format!("{:?}", dir_entry);
+        let expected = format!("DirEntry({:?})", dir_entry.0.path());
+        assert_eq!(actual, expected);
+    }
+
     #[test]
     fn read_dir_not_found() {
         let res = fs::read_dir("/path/that/does/not/exist");