[][src]Trait wasi_common::Handle

pub trait Handle {
    fn as_any(&self) -> &dyn Any;
fn try_clone(&self) -> Result<Box<dyn Handle>>;
fn get_file_type(&self) -> Filetype;
fn set_rights(&self, rights: HandleRights); fn get_rights(&self) -> HandleRights { ... }
fn is_directory(&self) -> bool { ... }
fn is_tty(&self) -> bool { ... }
fn advise(
        &self,
        _advice: Advice,
        _offset: Filesize,
        _len: Filesize
    ) -> Result<()> { ... }
fn allocate(&self, _offset: Filesize, _len: Filesize) -> Result<()> { ... }
fn datasync(&self) -> Result<()> { ... }
fn fdstat_get(&self) -> Result<Fdflags> { ... }
fn fdstat_set_flags(&self, _fdflags: Fdflags) -> Result<()> { ... }
fn filestat_get(&self) -> Result<Filestat> { ... }
fn filestat_set_size(&self, _st_size: Filesize) -> Result<()> { ... }
fn filestat_set_times(
        &self,
        _atim: Timestamp,
        _mtim: Timestamp,
        _fst_flags: Fstflags
    ) -> Result<()> { ... }
fn preadv(&self, _buf: &mut [IoSliceMut<'_>], _offset: u64) -> Result<usize> { ... }
fn pwritev(&self, _buf: &[IoSlice<'_>], _offset: u64) -> Result<usize> { ... }
fn read_vectored(&self, _iovs: &mut [IoSliceMut<'_>]) -> Result<usize> { ... }
fn readdir<'a>(
        &'a self,
        _cookie: Dircookie
    ) -> Result<Box<dyn Iterator<Item = Result<(Dirent, String)>> + 'a>> { ... }
fn seek(&self, _offset: SeekFrom) -> Result<u64> { ... }
fn sync(&self) -> Result<()> { ... }
fn write_vectored(&self, _iovs: &[IoSlice<'_>]) -> Result<usize> { ... }
fn create_directory(&self, _path: &str) -> Result<()> { ... }
fn filestat_get_at(&self, _path: &str, _follow: bool) -> Result<Filestat> { ... }
fn filestat_set_times_at(
        &self,
        _path: &str,
        _atim: Timestamp,
        _mtim: Timestamp,
        _fst_flags: Fstflags,
        _follow: bool
    ) -> Result<()> { ... }
fn openat(
        &self,
        _path: &str,
        _read: bool,
        _write: bool,
        _oflags: Oflags,
        _fd_flags: Fdflags
    ) -> Result<Box<dyn Handle>> { ... }
fn link(
        &self,
        _old_path: &str,
        _new_handle: Box<dyn Handle>,
        _new_path: &str,
        _follow: bool
    ) -> Result<()> { ... }
fn readlink(&self, _path: &str, _buf: &mut [u8]) -> Result<usize> { ... }
fn readlinkat(&self, _path: &str) -> Result<String> { ... }
fn remove_directory(&self, _path: &str) -> Result<()> { ... }
fn rename(
        &self,
        _old_path: &str,
        _new_handle: Box<dyn Handle>,
        _new_path: &str
    ) -> Result<()> { ... }
fn symlink(&self, _old_path: &str, _new_path: &str) -> Result<()> { ... }
fn unlink_file(&self, _path: &str) -> Result<()> { ... } }

Generic interface for all WASI-compatible handles. We currently group these into two groups:

  • OS-based resources (actual, real resources): OsFile, OsDir, OsOther, and Stdio,
  • virtual files and directories: VirtualDir, and InMemoryFile`.

Constructing Handles representing OS-based resources

Each type of handle can either be constructed directly (see docs entry for a specific handle type such as OsFile), or you can let the wasi_common crate's machinery work it out automatically for you using std::convert::TryInto from std::fs::File:

use std::convert::TryInto;
use wasi_common::Handle;
use std::fs::OpenOptions;

let some_file = OpenOptions::new().read(true).open("some_file").unwrap();
let wasi_handle: Box<dyn Handle> = some_file.try_into().unwrap();

Required methods

fn as_any(&self) -> &dyn Any

fn try_clone(&self) -> Result<Box<dyn Handle>>

fn get_file_type(&self) -> Filetype

fn set_rights(&self, rights: HandleRights)

Loading content...

Provided methods

fn get_rights(&self) -> HandleRights

fn is_directory(&self) -> bool

fn is_tty(&self) -> bool

Test whether this descriptor is considered a tty within WASI. Note that since WASI itself lacks an isatty syscall and relies on a conservative approximation, we use the same approximation here.

fn advise(
    &self,
    _advice: Advice,
    _offset: Filesize,
    _len: Filesize
) -> Result<()>

fn allocate(&self, _offset: Filesize, _len: Filesize) -> Result<()>

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

fn fdstat_get(&self) -> Result<Fdflags>

fn fdstat_set_flags(&self, _fdflags: Fdflags) -> Result<()>

fn filestat_get(&self) -> Result<Filestat>

fn filestat_set_size(&self, _st_size: Filesize) -> Result<()>

fn filestat_set_times(
    &self,
    _atim: Timestamp,
    _mtim: Timestamp,
    _fst_flags: Fstflags
) -> Result<()>

fn preadv(&self, _buf: &mut [IoSliceMut<'_>], _offset: u64) -> Result<usize>

fn pwritev(&self, _buf: &[IoSlice<'_>], _offset: u64) -> Result<usize>

fn read_vectored(&self, _iovs: &mut [IoSliceMut<'_>]) -> Result<usize>

fn readdir<'a>(
    &'a self,
    _cookie: Dircookie
) -> Result<Box<dyn Iterator<Item = Result<(Dirent, String)>> + 'a>>

fn seek(&self, _offset: SeekFrom) -> Result<u64>

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

fn write_vectored(&self, _iovs: &[IoSlice<'_>]) -> Result<usize>

fn create_directory(&self, _path: &str) -> Result<()>

fn filestat_get_at(&self, _path: &str, _follow: bool) -> Result<Filestat>

fn filestat_set_times_at(
    &self,
    _path: &str,
    _atim: Timestamp,
    _mtim: Timestamp,
    _fst_flags: Fstflags,
    _follow: bool
) -> Result<()>

fn openat(
    &self,
    _path: &str,
    _read: bool,
    _write: bool,
    _oflags: Oflags,
    _fd_flags: Fdflags
) -> Result<Box<dyn Handle>>

fn readlinkat(&self, _path: &str) -> Result<String>

fn remove_directory(&self, _path: &str) -> Result<()>

fn rename(
    &self,
    _old_path: &str,
    _new_handle: Box<dyn Handle>,
    _new_path: &str
) -> Result<()>

Loading content...

Implementors

impl Handle for OsDir[src]

impl Handle for OsFile[src]

impl Handle for OsOther[src]

impl Handle for InMemoryFile[src]

impl Handle for VirtualDir[src]

impl<R: Read + Any> Handle for ReadPipe<R>[src]

impl<W: Write + Any> Handle for WritePipe<W>[src]

Loading content...