Skip to content

Commit 9b25f10

Browse files
author
Jonathan Turner
authored
Rollup merge of #36631 - frewsxcv:dir-entry-debug, r=sfackler
Implement Debug for DirEntry. None
2 parents 9c469ff + 8b8681e commit 9b25f10

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/libstd/fs.rs

+21
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,15 @@ impl DirEntry {
10551055
}
10561056
}
10571057

1058+
#[stable(feature = "dir_entry_debug", since = "1.13.0")]
1059+
impl fmt::Debug for DirEntry {
1060+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1061+
f.debug_tuple("DirEntry")
1062+
.field(&self.path())
1063+
.finish()
1064+
}
1065+
}
1066+
10581067
impl AsInner<fs_imp::DirEntry> for DirEntry {
10591068
fn as_inner(&self) -> &fs_imp::DirEntry { &self.0 }
10601069
}
@@ -2641,6 +2650,18 @@ mod tests {
26412650
}
26422651
}
26432652

2653+
#[test]
2654+
fn dir_entry_debug() {
2655+
let tmpdir = tmpdir();
2656+
let file_path = &tmpdir.join("b");
2657+
File::create(file_path).unwrap();
2658+
let mut read_dir = tmpdir.path().read_dir().unwrap();
2659+
let dir_entry = read_dir.next().unwrap().unwrap();
2660+
let actual = format!("{:?}", dir_entry);
2661+
let expected = format!("DirEntry(\"{}\")", file_path.display());
2662+
assert_eq!(actual, expected);
2663+
}
2664+
26442665
#[test]
26452666
fn read_dir_not_found() {
26462667
let res = fs::read_dir("/path/that/does/not/exist");

0 commit comments

Comments
 (0)