Skip to main content

WasiHttpView

Trait WasiHttpView 

Source
pub trait WasiHttpView {
    // Required method
    fn http(&mut self) -> WasiHttpCtxView<'_>;
}
Available on crate feature p2 only.
Expand description

A trait used to project state that this crate needs to implement wasi:http from the self type.

This trait is used in add_to_linker_sync and add_to_linker_async for example as a bound on T in Store<T>. This is used to access data from T, the data within a Store, an instance of WasiHttpCtxView. The WasiHttpCtxView contains contextual information such as the [ResourceTable] for the store, HTTP context info in WasiHttpCtx, and any hooks via WasiHttpHooks if the embedder desires.

§Example

use wasmtime::component::ResourceTable;
use wasmtime_wasi_http::WasiHttpCtx;
use wasmtime_wasi_http::p2::{WasiHttpView, WasiHttpCtxView};

struct MyState {
    http_ctx: WasiHttpCtx,
    table: ResourceTable,
}

impl WasiHttpView for MyState {
    fn http(&mut self) -> WasiHttpCtxView<'_> {
        WasiHttpCtxView {
            ctx: &mut self.http_ctx,
            table: &mut self.table,
            hooks: Default::default(),
        }
    }
}

Required Methods§

Source

fn http(&mut self) -> WasiHttpCtxView<'_>

Returns an instance of WasiHttpCtxView projected out of self.

Implementors§