wasmtime_wasi

Trait WasiView

source
pub trait WasiView: Send {
    // Required methods
    fn table(&mut self) -> &mut ResourceTable;
    fn ctx(&mut self) -> &mut WasiCtx;
}
Expand description

A trait which provides access to internal WASI state.

This trait is the basis of implementation of all traits in this crate. All traits are implemented like:

impl<T: WasiView> bindings::wasi::Host for T {
    // ...
}

For a Store<T> this trait will be implemented for the T. This also corresponds to the T in Linker<T>.

§Example

use wasmtime_wasi::{WasiCtx, ResourceTable, WasiView, WasiCtxBuilder};

struct MyState {
    ctx: WasiCtx,
    table: ResourceTable,
}

impl WasiView for MyState {
    fn ctx(&mut self) -> &mut WasiCtx { &mut self.ctx }
    fn table(&mut self) -> &mut ResourceTable { &mut self.table }
}

impl MyState {
    fn new() -> MyState {
        let mut wasi = WasiCtxBuilder::new();
        wasi.arg("./foo.wasm");
        wasi.arg("--help");
        wasi.env("FOO", "bar");

        MyState {
            ctx: wasi.build(),
            table: ResourceTable::new(),
        }
    }
}

Required Methods§

source

fn table(&mut self) -> &mut ResourceTable

Yields mutable access to the internal resource management that this context contains.

Embedders can add custom resources to this table as well to give resources to wasm as well.

source

fn ctx(&mut self) -> &mut WasiCtx

Yields mutable access to the configuration used for this context.

The returned type is created through WasiCtxBuilder.

Implementations on Foreign Types§

source§

impl<T: ?Sized + WasiView> WasiView for &mut T

source§

fn table(&mut self) -> &mut ResourceTable

source§

fn ctx(&mut self) -> &mut WasiCtx

source§

impl<T: ?Sized + WasiView> WasiView for Box<T>

source§

fn table(&mut self) -> &mut ResourceTable

source§

fn ctx(&mut self) -> &mut WasiCtx

Implementors§

source§

impl WasiView for WasiP1Ctx

Available on crate feature preview1 only.
source§

impl<T: WasiView> WasiView for WasiImpl<T>