wasmtime_wasi_io

Function add_to_linker_async

Source
pub fn add_to_linker_async<T: IoView>(l: &mut Linker<T>) -> Result<()>
Expand description

Add the wasi-io host implementation from this crate into the linker provided.

This function will add the async variant of all interfaces into the Linker provided. By async this means that this function is only compatible with Config::async_support(true). For embeddings with async support disabled, you’ll need to use other crates, such as the wasmtime-wasi crate, which provides an add_to_linker_sync that includes an appropriate wasi-io implementation based on this crate’s.

This function will add all interfaces implemented by this crate to the Linker, which corresponds to the wasi:io/imports world supported by this crate.

§Example

use wasmtime::{Engine, Result, Store, Config};
use wasmtime::component::{ResourceTable, Linker};
use wasmtime_wasi_io::IoView;

fn main() -> Result<()> {
    let mut config = Config::new();
    config.async_support(true);
    let engine = Engine::new(&config)?;

    let mut linker = Linker::<MyState>::new(&engine);
    wasmtime_wasi_io::add_to_linker_async(&mut linker)?;
    // ... add any further functionality to `linker` if desired ...

    let mut store = Store::new(
        &engine,
        MyState {
            table: ResourceTable::new(),
        },
    );

    // ... use `linker` to instantiate within `store` ...

    Ok(())
}

struct MyState {
    table: ResourceTable,
}

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