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<()> { ... }
}
wasi_ext
#71213)Expand description
WASI-specific extensions to File
.
Required Methods§
sourcefn read_vectored_at(
&self,
bufs: &mut [IoSliceMut<'_>],
offset: u64
) -> Result<usize>
fn read_vectored_at( &self, bufs: &mut [IoSliceMut<'_>], offset: u64 ) -> Result<usize>
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.
sourcefn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> Result<usize>
fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> Result<usize>
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.
sourcefn tell(&self) -> Result<u64>
fn tell(&self) -> Result<u64>
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.
sourcefn fdstat_set_flags(&self, flags: u16) -> Result<()>
fn fdstat_set_flags(&self, flags: u16) -> Result<()>
wasi_ext
#71213)Adjust the flags associated with this file.
This corresponds to the fd_fdstat_set_flags
syscall.
sourcefn fdstat_set_rights(&self, rights: u64, inheriting: u64) -> Result<()>
fn fdstat_set_rights(&self, rights: u64, inheriting: u64) -> Result<()>
wasi_ext
#71213)Adjust the rights associated with this file.
This corresponds to the fd_fdstat_set_rights
syscall.
sourcefn advise(&self, offset: u64, len: u64, advice: u8) -> Result<()>
fn advise(&self, offset: u64, len: u64, advice: u8) -> Result<()>
wasi_ext
#71213)Provide file advisory information on a file descriptor.
This corresponds to the fd_advise
syscall.
sourcefn allocate(&self, offset: u64, len: u64) -> Result<()>
fn allocate(&self, offset: u64, len: u64) -> Result<()>
wasi_ext
#71213)Force the allocation of space in a file.
This corresponds to the fd_allocate
syscall.
sourcefn create_directory<P: AsRef<Path>>(&self, dir: P) -> Result<()>
fn create_directory<P: AsRef<Path>>(&self, dir: P) -> Result<()>
wasi_ext
#71213)Create a directory.
This corresponds to the path_create_directory
syscall.
sourcefn read_link<P: AsRef<Path>>(&self, path: P) -> Result<PathBuf>
fn read_link<P: AsRef<Path>>(&self, path: P) -> Result<PathBuf>
wasi_ext
#71213)Read the contents of a symbolic link.
This corresponds to the path_readlink
syscall.
sourcefn metadata_at<P: AsRef<Path>>(
&self,
lookup_flags: u32,
path: P
) -> Result<Metadata>
fn metadata_at<P: AsRef<Path>>( &self, lookup_flags: u32, path: P ) -> Result<Metadata>
wasi_ext
#71213)Return the attributes of a file or directory.
This corresponds to the path_filestat_get
syscall.
Provided Methods§
sourcefn read_at(&self, buf: &mut [u8], offset: u64) -> Result<usize>
fn read_at(&self, buf: &mut [u8], offset: u64) -> Result<usize>
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.
1.33.0 · sourcefn read_exact_at(&self, buf: &mut [u8], offset: u64) -> Result<()>
fn read_exact_at(&self, buf: &mut [u8], offset: u64) -> Result<()>
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.
sourcefn write_at(&self, buf: &[u8], offset: u64) -> Result<usize>
fn write_at(&self, buf: &[u8], offset: u64) -> Result<usize>
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.
1.33.0 · sourcefn write_all_at(&self, buf: &[u8], offset: u64) -> Result<()>
fn write_all_at(&self, buf: &[u8], offset: u64) -> Result<()>
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.