Struct RootDir

Source
pub struct RootDir(/* private fields */);
Expand description

Wrapper for a cap_std::fs::Dir that is defined to use `RESOLVE_IN_ROOT`` semantics when opening files and subdirectories. This currently only offers a subset of the methods, primarily reading.

§When and how to use this

In general, if your use case possibly involves reading files that may be absolute symlinks, or relative symlinks that may go outside the provided directory, you will need to use this API instead of cap_std::fs::Dir.

§Performing writes

If you want to simultaneously perform other operations (such as writing), at the moment it requires explicitly maintaining a duplicate copy of a cap_std::fs::Dir instance, or using direct rustix::fs APIs.

Implementations§

Source§

impl RootDir

Source

pub fn new(src: &Dir, path: impl AsRef<Path>) -> Result<Self>

Create a new instance from an existing cap_std::fs::Dir instance.

Source

pub fn open_ambient_root( path: impl AsRef<Path>, authority: AmbientAuthority, ) -> Result<Self>

Create a new instance from an ambient path.

Source

pub fn open(&self, path: impl AsRef<Path>) -> Result<File>

Open a file in this root, read-only.

Source

pub fn open_optional(&self, path: impl AsRef<Path>) -> Result<Option<File>>

Open a file read-only, but return Ok(None) if it does not exist.

Source

pub fn read(&self, path: impl AsRef<Path>) -> Result<Vec<u8>>

Read the contents of a file into a vector.

Source

pub fn read_to_string(&self, path: impl AsRef<Path>) -> Result<String>

Read the contents of a file as a string.

Source

pub fn entries(&self) -> Result<ReadDir>

Return the directory entries.

Source

pub fn read_dir(&self, path: impl AsRef<Path>) -> Result<ReadDir>

Return the directory entries of the target subdirectory.

Source

pub fn reopen_cap_std(&self) -> Result<Dir>

Create a cap_std::fs::Dir pointing to the same directory as self. This view will not use RESOLVE_IN_ROOT.

Trait Implementations§

Source§

impl Debug for RootDir

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Dir> for RootDir

Source§

fn from(dir: Dir) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.