Function wasmtime_wasi_http::add_to_linker_async
source · pub fn add_to_linker_async<T>(l: &mut Linker<T>) -> Result<()>where
T: WasiHttpView + WasiView,
Expand description
Add all of the wasi:http/proxy
world’s interfaces to a wasmtime::component::Linker
.
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 see add_to_linker_sync
instead.
§Example
use wasmtime::{Engine, Result, Config};
use wasmtime::component::{ResourceTable, Linker};
use wasmtime_wasi::{WasiCtx, WasiView};
use wasmtime_wasi_http::{WasiHttpCtx, WasiHttpView};
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_http::add_to_linker_async(&mut linker)?;
// ... add any further functionality to `linker` if desired ...
Ok(())
}
struct MyState {
ctx: WasiCtx,
http_ctx: WasiHttpCtx,
table: ResourceTable,
}
impl WasiHttpView for MyState {
fn ctx(&mut self) -> &mut WasiHttpCtx { &mut self.http_ctx }
fn table(&mut self) -> &mut ResourceTable { &mut self.table }
}
impl WasiView for MyState {
fn ctx(&mut self) -> &mut WasiCtx { &mut self.ctx }
fn table(&mut self) -> &mut ResourceTable { &mut self.table }
}