pub fn add_to_linker_sync<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 sync
variant of all interfaces into the
Linker
provided. For embeddings with async support see
add_to_linker_async
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 config = Config::default();
let engine = Engine::new(&config)?;
let mut linker = Linker::<MyState>::new(&engine);
wasmtime_wasi_http::add_to_linker_sync(&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 }
}