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§
sourcefn table(&mut self) -> &mut ResourceTable
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.
sourcefn ctx(&mut self) -> &mut WasiCtx
fn ctx(&mut self) -> &mut WasiCtx
Yields mutable access to the configuration used for this context.
The returned type is created through WasiCtxBuilder
.