use std::sync::Arc;
use uni_plugin::{CapabilitySet, HttpEgress};
use wasmtime_wasi::{ResourceTable, WasiCtx, WasiCtxBuilder, WasiCtxView, WasiView};
pub struct HostState {
pub effective: CapabilitySet,
pub http: Option<Arc<dyn HttpEgress>>,
pub wasi: WasiCtx,
pub table: ResourceTable,
}
impl HostState {
#[must_use]
pub fn new(effective: CapabilitySet, http: Option<Arc<dyn HttpEgress>>) -> Self {
let wasi = WasiCtxBuilder::new().build();
Self {
effective,
http,
wasi,
table: ResourceTable::new(),
}
}
}
impl std::fmt::Debug for HostState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("HostState")
.field("effective", &self.effective)
.field("http", &self.http.is_some())
.finish_non_exhaustive()
}
}
impl WasiView for HostState {
fn ctx(&mut self) -> WasiCtxView<'_> {
WasiCtxView {
ctx: &mut self.wasi,
table: &mut self.table,
}
}
}