std::os::wasi::fs

Trait FileExt

Source
pub trait FileExt {
Show 16 methods // Required methods fn read_vectored_at( &self, bufs: &mut [IoSliceMut<'_>], offset: u64, ) -> Result<usize>; fn write_vectored_at( &self, bufs: &[IoSlice<'_>], offset: u64, ) -> Result<usize>; fn tell(&self) -> Result<u64>; fn fdstat_set_flags(&self, flags: u16) -> Result<()>; fn fdstat_set_rights(&self, rights: u64, inheriting: u64) -> Result<()>; fn advise(&self, offset: u64, len: u64, advice: u8) -> Result<()>; fn allocate(&self, offset: u64, len: u64) -> Result<()>; fn create_directory<P: AsRef<Path>>(&self, dir: P) -> Result<()>; fn read_link<P: AsRef<Path>>(&self, path: P) -> Result<PathBuf>; fn metadata_at<P: AsRef<Path>>( &self, lookup_flags: u32, path: P, ) -> Result<Metadata>; fn remove_file<P: AsRef<Path>>(&self, path: P) -> Result<()>; fn remove_directory<P: AsRef<Path>>(&self, path: P) -> Result<()>; // Provided methods fn read_at(&self, buf: &mut [u8], offset: u64) -> Result<usize> { ... } fn read_exact_at(&self, buf: &mut [u8], offset: u64) -> Result<()> { ... } fn write_at(&self, buf: &[u8], offset: u64) -> Result<usize> { ... } fn write_all_at(&self, buf: &[u8], offset: u64) -> Result<()> { ... }
}
πŸ”¬This is a nightly-only experimental API. (wasi_ext #71213)
Available on WASI only.
Expand description

WASI-specific extensions to File.

Required Methods§

Source

fn read_vectored_at( &self, bufs: &mut [IoSliceMut<'_>], offset: u64, ) -> Result<usize>

πŸ”¬This is a nightly-only experimental API. (wasi_ext #71213)

Reads a number of bytes starting from a given offset.

Returns the number of bytes read.

The offset is relative to the start of the file and thus independent from the current cursor.

The current file cursor is not affected by this function.

Note that similar to File::read_vectored, it is not an error to return with a short read.

Source

fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> Result<usize>

πŸ”¬This is a nightly-only experimental API. (wasi_ext #71213)

Writes a number of bytes starting from a given offset.

Returns the number of bytes written.

The offset is relative to the start of the file and thus independent from the current cursor.

The current file cursor is not affected by this function.

When writing beyond the end of the file, the file is appropriately extended and the intermediate bytes are initialized with the value 0.

Note that similar to File::write_vectored, it is not an error to return a short write.

Source

fn tell(&self) -> Result<u64>

πŸ”¬This is a nightly-only experimental API. (wasi_ext #71213)

Returns the current position within the file.

This corresponds to the fd_tell syscall and is similar to seek where you offset 0 bytes from the current position.

Source

fn fdstat_set_flags(&self, flags: u16) -> Result<()>

πŸ”¬This is a nightly-only experimental API. (wasi_ext #71213)

Adjusts the flags associated with this file.

This corresponds to the fd_fdstat_set_flags syscall.

Source

fn fdstat_set_rights(&self, rights: u64, inheriting: u64) -> Result<()>

πŸ”¬This is a nightly-only experimental API. (wasi_ext #71213)

Adjusts the rights associated with this file.

This corresponds to the fd_fdstat_set_rights syscall.

Source

fn advise(&self, offset: u64, len: u64, advice: u8) -> Result<()>

πŸ”¬This is a nightly-only experimental API. (wasi_ext #71213)

Provides file advisory information on a file descriptor.

This corresponds to the fd_advise syscall.

Source

fn allocate(&self, offset: u64, len: u64) -> Result<()>

πŸ”¬This is a nightly-only experimental API. (wasi_ext #71213)

Forces the allocation of space in a file.

This corresponds to the fd_allocate syscall.

Source

fn create_directory<P: AsRef<Path>>(&self, dir: P) -> Result<()>

πŸ”¬This is a nightly-only experimental API. (wasi_ext #71213)

Creates a directory.

This corresponds to the path_create_directory syscall.

πŸ”¬This is a nightly-only experimental API. (wasi_ext #71213)

Reads the contents of a symbolic link.

This corresponds to the path_readlink syscall.

Source

fn metadata_at<P: AsRef<Path>>( &self, lookup_flags: u32, path: P, ) -> Result<Metadata>

πŸ”¬This is a nightly-only experimental API. (wasi_ext #71213)

Returns the attributes of a file or directory.

This corresponds to the path_filestat_get syscall.

Source

fn remove_file<P: AsRef<Path>>(&self, path: P) -> Result<()>

πŸ”¬This is a nightly-only experimental API. (wasi_ext #71213)

Unlinks a file.

This corresponds to the path_unlink_file syscall.

Source

fn remove_directory<P: AsRef<Path>>(&self, path: P) -> Result<()>

πŸ”¬This is a nightly-only experimental API. (wasi_ext #71213)

Removes a directory.

This corresponds to the path_remove_directory syscall.

Provided Methods§

Source

fn read_at(&self, buf: &mut [u8], offset: u64) -> Result<usize>

πŸ”¬This is a nightly-only experimental API. (wasi_ext #71213)

Reads a number of bytes starting from a given offset.

Returns the number of bytes read.

The offset is relative to the start of the file and thus independent from the current cursor.

The current file cursor is not affected by this function.

Note that similar to File::read, it is not an error to return with a short read.

Source

fn read_exact_at(&self, buf: &mut [u8], offset: u64) -> Result<()>

πŸ”¬This is a nightly-only experimental API. (wasi_ext #71213)

Reads the exact number of byte required to fill buf from the given offset.

The offset is relative to the start of the file and thus independent from the current cursor.

The current file cursor is not affected by this function.

Similar to Read::read_exact but uses read_at instead of read.

Β§Errors

If this function encounters an error of the kind io::ErrorKind::Interrupted then the error is ignored and the operation will continue.

If this function encounters an β€œend of file” before completely filling the buffer, it returns an error of the kind io::ErrorKind::UnexpectedEof. The contents of buf are unspecified in this case.

If any other read error is encountered then this function immediately returns. The contents of buf are unspecified in this case.

If this function returns an error, it is unspecified how many bytes it has read, but it will never read more than would be necessary to completely fill the buffer.

Source

fn write_at(&self, buf: &[u8], offset: u64) -> Result<usize>

πŸ”¬This is a nightly-only experimental API. (wasi_ext #71213)

Writes a number of bytes starting from a given offset.

Returns the number of bytes written.

The offset is relative to the start of the file and thus independent from the current cursor.

The current file cursor is not affected by this function.

When writing beyond the end of the file, the file is appropriately extended and the intermediate bytes are initialized with the value 0.

Note that similar to File::write, it is not an error to return a short write.

Source

fn write_all_at(&self, buf: &[u8], offset: u64) -> Result<()>

πŸ”¬This is a nightly-only experimental API. (wasi_ext #71213)

Attempts to write an entire buffer starting from a given offset.

The offset is relative to the start of the file and thus independent from the current cursor.

The current file cursor is not affected by this function.

This method will continuously call write_at until there is no more data to be written or an error of non-io::ErrorKind::Interrupted kind is returned. This method will not return until the entire buffer has been successfully written or such an error occurs. The first error that is not of io::ErrorKind::Interrupted kind generated from this method will be returned.

Β§Errors

This function will return the first error of non-io::ErrorKind::Interrupted kind that write_at returns.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§