use crate::WasiCtx;
use wasmtime::component::ResourceTable;
pub trait WasiView: Send {
fn ctx(&mut self) -> WasiCtxView<'_>;
}
pub struct WasiCtxView<'a> {
pub ctx: &'a mut WasiCtx,
pub table: &'a mut ResourceTable,
}
impl<T: WasiView> crate::cli::WasiCliView for T {
fn cli(&mut self) -> crate::cli::WasiCliCtxView<'_> {
let WasiCtxView { ctx, table } = self.ctx();
crate::cli::WasiCliCtxView {
ctx: &mut ctx.cli,
table,
}
}
}
impl<T: WasiView> crate::clocks::WasiClocksView for T {
fn clocks(&mut self) -> crate::clocks::WasiClocksCtxView<'_> {
let WasiCtxView { ctx, table } = self.ctx();
crate::clocks::WasiClocksCtxView {
ctx: &mut ctx.clocks,
table,
}
}
}
impl<T: WasiView> crate::filesystem::WasiFilesystemView for T {
fn filesystem(&mut self) -> crate::filesystem::WasiFilesystemCtxView<'_> {
let WasiCtxView { ctx, table } = self.ctx();
crate::filesystem::WasiFilesystemCtxView {
ctx: &mut ctx.filesystem,
table,
}
}
}
impl<T: WasiView> crate::random::WasiRandomView for T {
fn random(&mut self) -> &mut crate::random::WasiRandomCtx {
&mut self.ctx().ctx.random
}
}
impl<T: WasiView> crate::sockets::WasiSocketsView for T {
fn sockets(&mut self) -> crate::sockets::WasiSocketsCtxView<'_> {
let WasiCtxView { ctx, table } = self.ctx();
crate::sockets::WasiSocketsCtxView {
ctx: &mut ctx.sockets,
table,
}
}
}