Skip to content

Commit 95e84f4

Browse files
authored
fs_utf8/Dir: impl AsRef<crate::fs::Dir> (#364)
This allows an API like: ``` fn foo(d: impl AsRef<Dir>) { ... } ``` to accept either a `Dir` or a `DirUtf8`. I don't know that I'll do this much, but I think it can make sense.
1 parent 401a42c commit 95e84f4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

cap-std/src/fs_utf8/dir.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl Dir {
9494
#[inline]
9595
pub fn open_dir<P: AsRef<Utf8Path>>(&self, path: P) -> io::Result<Self> {
9696
let path = from_utf8(path.as_ref())?;
97-
self.cap_std.open_dir(path).map(Self::from_cap_std)
97+
self.as_ref().open_dir(path).map(Self::from_cap_std)
9898
}
9999

100100
/// Creates a new, empty directory at the provided path.
@@ -838,3 +838,9 @@ impl fmt::Debug for Dir {
838838
self.cap_std.fmt(f)
839839
}
840840
}
841+
842+
impl AsRef<crate::fs::Dir> for Dir {
843+
fn as_ref(&self) -> &crate::fs::Dir {
844+
self.as_cap_std()
845+
}
846+
}

0 commit comments

Comments
 (0)