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>