Struct wasi_common::fs::Dir

source ·
pub struct Dir<'ctx> { /* private fields */ }
Expand description

A reference to an open directory on the filesystem.

TODO: Implement Dir-using versions of std::fs’s free functions: copy, create_dir, create_dir_all, hard_link, metadata, read_link, read_to_string, remove_dir, remove_dir_all, remove_file, rename, set_permissions, symlink_metadata, and write.

Unlike std::fs, this API has no canonicalize, because absolute paths don’t interoperate well with the capability-oriented security model.

Implementations§

source§

impl<'ctx> Dir<'ctx>

source

pub unsafe fn from_raw_wasi_fd(ctx: &'ctx mut WasiCtx, fd: u32) -> Self

Constructs a new instance of Self from the given raw WASI file descriptor.

source

pub fn open_file<P: AsRef<Path>>(&mut self, path: P) -> Result<File<'_>>

Attempts to open a file in read-only mode.

This corresponds to std::fs::File::open, but only accesses paths relative to and within self.

TODO: Not yet implemented. Refactor the hostcalls functions to split out the encoding/decoding parts from the underlying functionality, so that we can call into the underlying functionality directly.

source

pub fn open_file_with<P: AsRef<Path>>( &mut self, path: P, options: &OpenOptions, ) -> Result<File<'_>>

Opens a file at path with the options specified by self.

This corresponds to std::fs::OpenOptions::open.

Instead of being a method on OpenOptions, this is a method on Dir, and it only accesses functions relative to and within self.

TODO: Not yet implemented.

source

pub fn open_dir<P: AsRef<Path>>(&mut self, path: P) -> Result<Self>

Attempts to open a directory.

TODO: Not yet implemented. See the comment in open_file.

source

pub fn create_file<P: AsRef<Path>>(&mut self, path: P) -> Result<File<'_>>

Opens a file in write-only mode.

This corresponds to std::fs::File::create, but only accesses paths relative to and within self.

TODO: Not yet implemented. See the comment in open_file.

source

pub fn read(&mut self) -> Result<ReadDir>

Returns an iterator over the entries within a directory.

This corresponds to std::fs::read_dir, but reads the directory represented by self.

TODO: Not yet implemented. We may need to wait until we have the ability to duplicate file descriptors before we can implement read safely. For now, use into_read instead.

source

pub fn into_read(self) -> ReadDir

Consumes self and returns an iterator over the entries within a directory in the manner of read.

source

pub fn read_file<P: AsRef<Path>>(&mut self, path: P) -> Result<Vec<u8>>

Read the entire contents of a file into a bytes vector.

This corresponds to std::fs::read, but only accesses paths relative to and within self.

source

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

Returns an iterator over the entries within a directory.

This corresponds to std::fs::read_dir, but only accesses paths relative to and within self.

Trait Implementations§

source§

impl<'ctx> Drop for Dir<'ctx>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'ctx> Freeze for Dir<'ctx>

§

impl<'ctx> RefUnwindSafe for Dir<'ctx>

§

impl<'ctx> Send for Dir<'ctx>

§

impl<'ctx> Sync for Dir<'ctx>

§

impl<'ctx> Unpin for Dir<'ctx>

§

impl<'ctx> !UnwindSafe for Dir<'ctx>

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>,

§

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>,

§

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.