wasmer_vfs

Trait VirtualFile

Source
pub trait VirtualFile:
    Debug
    + Write
    + Read
    + Seek
    + Upcastable {
    // Required methods
    fn last_accessed(&self) -> u64;
    fn last_modified(&self) -> u64;
    fn created_time(&self) -> u64;
    fn size(&self) -> u64;
    fn set_len(&mut self, new_size: u64) -> Result<()>;
    fn unlink(&mut self) -> Result<()>;

    // Provided methods
    fn sync_to_disk(&self) -> Result<()> { ... }
    fn bytes_available(&self) -> Result<usize> { ... }
    fn bytes_available_read(&self) -> Result<Option<usize>> { ... }
    fn bytes_available_write(&self) -> Result<Option<usize>> { ... }
    fn is_open(&self) -> bool { ... }
    fn get_fd(&self) -> Option<FileDescriptor> { ... }
}
Expand description

This trait relies on your file closing when it goes out of scope via Drop

Required Methods§

Source

fn last_accessed(&self) -> u64

the last time the file was accessed in nanoseconds as a UNIX timestamp

Source

fn last_modified(&self) -> u64

the last time the file was modified in nanoseconds as a UNIX timestamp

Source

fn created_time(&self) -> u64

the time at which the file was created in nanoseconds as a UNIX timestamp

Source

fn size(&self) -> u64

the size of the file in bytes

Source

fn set_len(&mut self, new_size: u64) -> Result<()>

Change the size of the file, if the new_size is greater than the current size the extra bytes will be allocated and zeroed

Request deletion of the file

Provided Methods§

Source

fn sync_to_disk(&self) -> Result<()>

Store file contents and metadata to disk Default implementation returns Ok(()). You should implement this method if you care about flushing your cache to permanent storage

Source

fn bytes_available(&self) -> Result<usize>

Returns the number of bytes available. This function must not block

Source

fn bytes_available_read(&self) -> Result<Option<usize>>

Returns the number of bytes available. This function must not block Defaults to None which means the number of bytes is unknown

Source

fn bytes_available_write(&self) -> Result<Option<usize>>

Returns the number of bytes available. This function must not block Defaults to None which means the number of bytes is unknown

Source

fn is_open(&self) -> bool

Indicates if the file is opened or closed. This function must not block Defaults to a status of being constantly open

Source

fn get_fd(&self) -> Option<FileDescriptor>

Used for polling. Default returns None because this method cannot be implemented for most types Returns the underlying host fd

Implementors§

Source§

impl VirtualFile for File

Source§

impl VirtualFile for wasmer_vfs::host_fs::Stderr

Source§

impl VirtualFile for wasmer_vfs::host_fs::Stdin

Source§

impl VirtualFile for wasmer_vfs::host_fs::Stdout

Source§

impl VirtualFile for wasmer_vfs::mem_fs::Stderr

Source§

impl VirtualFile for wasmer_vfs::mem_fs::Stdin

Source§

impl VirtualFile for wasmer_vfs::mem_fs::Stdout

Source§

impl VirtualFile for WebCFile