Struct wasi_common::fs::File
source · pub struct File<'ctx> { /* private fields */ }
Expand description
A reference to an open file on the filesystem.
This corresponds to std::fs::File
.
Note that this File
has no open
or create
methods. To open or create
a file, you must first obtain a Dir
containing the file, and then call
Dir::open_file
or Dir::create_file
.
Implementations§
source§impl<'ctx> File<'ctx>
impl<'ctx> File<'ctx>
sourcepub unsafe fn from_raw_wasi_fd(ctx: &'ctx mut WasiCtx, fd: u32) -> Self
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.
This corresponds to std::fs::File::from_raw_fd
.
sourcepub fn sync_all(&self) -> Result<()>
pub fn sync_all(&self) -> Result<()>
Attempts to sync all OS-internal metadata to disk.
This corresponds to std::fs::File::sync_all
.
sourcepub fn sync_data(&self) -> Result<()>
pub fn sync_data(&self) -> Result<()>
This function is similar to sync_all
, except that it may not synchronize
file metadata to the filesystem.
This corresponds to std::fs::File::sync_data
.
sourcepub fn set_len(&self, size: u64) -> Result<()>
pub fn set_len(&self, size: u64) -> Result<()>
Truncates or extends the underlying file, updating the size of this file to become size.
This corresponds to std::fs::File::set_len
.
sourcepub fn metadata(&self) -> Result<Metadata>
pub fn metadata(&self) -> Result<Metadata>
Queries metadata about the underlying file.
This corresponds to std::fs::File::metadata
.
Trait Implementations§
source§impl<'ctx> Read for File<'ctx>
impl<'ctx> Read for File<'ctx>
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
TODO: Not yet implemented. See the comment in Dir::open_file
.
1.36.0 · source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf
. Read more1.0.0 · source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read more1.6.0 · source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moresource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read more