Skip to content

Commit

Permalink
fs_utf8: Add as_cap_std() (#357)
Browse files Browse the repository at this point in the history
I'm looking at adding support in https://github.com/coreos/cap-std-ext/
for `fs_utf8`, and doing so really wants access to the currently
internal `cap_std` member in order to share code - in the
same way basically all the implementation functions here
just delgate to the underlying `Dir`.

I changed one usage to call this helper.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters authored Jun 28, 2024
1 parent 1dc17d3 commit 68cefe7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cap-std/src/fs_utf8/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,22 @@ impl Dir {
Self { cap_std }
}

/// Return a view of this directory as a [`cap_std::fs::Dir`]. This
/// is often useful in order to write shared functions which can operate
/// on either type.
#[inline]
pub fn as_cap_std(&self) -> &crate::fs::Dir {
&self.cap_std
}

/// Attempts to open a file in read-only mode.
///
/// This corresponds to [`std::fs::File::open`], but only accesses paths
/// relative to `self`.
#[inline]
pub fn open<P: AsRef<Utf8Path>>(&self, path: P) -> io::Result<File> {
let path = from_utf8(path.as_ref())?;
self.cap_std.open(path).map(File::from_cap_std)
self.as_cap_std().open(path).map(File::from_cap_std)
}

/// Opens a file at `path` with the options specified by `options`.
Expand Down

0 comments on commit 68cefe7

Please sign in to comment.