Trait FileExt
trait FileExt
WASI-specific extensions to File.
Required Methods
fn read_at(self: &Self, buf: &mut [u8], offset: u64) -> io::Result<usize>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.fn read_vectored_at(self: &Self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize>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.fn read_buf_at(self: &Self, buf: BorrowedCursor<'_>, offset: u64) -> io::Result<()>Reads some bytes starting from a given offset into the buffer.
This equivalent to the
read_atmethod, except that it is passed aBorrowedCursorrather than&mut [u8]to allow use with uninitialized buffers. The new data will be appended to any existing contents ofbuf.fn write_at(self: &Self, buf: &[u8], offset: u64) -> io::Result<usize>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.fn write_vectored_at(self: &Self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize>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.
Provided Methods
fn read_exact_at(self: &Self, buf: &mut [u8], offset: u64) -> io::Result<()>Reads the exact number of byte required to fill
buffrom 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_exactbut usesread_atinstead ofread.Errors
If this function encounters an error of the kind
io::ErrorKind::Interruptedthen 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 ofbufare unspecified in this case.If any other read error is encountered then this function immediately returns. The contents of
bufare 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.
fn write_all_at(self: &Self, buf: &[u8], offset: u64) -> io::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_atuntil there is no more data to be written or an error of non-io::ErrorKind::Interruptedkind 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 ofio::ErrorKind::Interruptedkind generated from this method will be returned.Errors
This function will return the first error of non-
io::ErrorKind::Interruptedkind thatwrite_atreturns.
Implementors
impl FileExt for crate::fs::File