Skip to content

Commit f2c53ea

Browse files
authored
Auto merge of #36631 - frewsxcv:dir-entry-debug, r=sfackler
Implement Debug for DirEntry. None
2 parents 533c04d + 6b697a3 commit f2c53ea

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/libstd/fs.rs

+20
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,17 @@ mod tests {
26412650
}
26422651
}
26432652

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

0 commit comments

Comments
 (0)