Skip to content

Commit

Permalink
fs_utf8/Dir: impl AsRef<crate::fs::Dir> (#364)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cgwalters authored Aug 29, 2024
1 parent 401a42c commit 95e84f4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cap-std/src/fs_utf8/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Dir {
#[inline]
pub fn open_dir<P: AsRef<Utf8Path>>(&self, path: P) -> io::Result<Self> {
let path = from_utf8(path.as_ref())?;
self.cap_std.open_dir(path).map(Self::from_cap_std)
self.as_ref().open_dir(path).map(Self::from_cap_std)
}

/// Creates a new, empty directory at the provided path.
Expand Down Expand Up @@ -838,3 +838,9 @@ impl fmt::Debug for Dir {
self.cap_std.fmt(f)
}
}

impl AsRef<crate::fs::Dir> for Dir {
fn as_ref(&self) -> &crate::fs::Dir {
self.as_cap_std()
}
}

0 comments on commit 95e84f4

Please sign in to comment.