wrpc_runtime_wasmtime/rpc/host/
context.rs

1use wasmtime::component::Resource;
2use wrpc_transport::Invoke;
3
4use crate::bindings::rpc::context::{Context, Host, HostContext};
5use crate::rpc::WrpcRpcImpl;
6use crate::{WrpcView, WrpcViewExt as _};
7
8impl<T: WrpcView> Host for WrpcRpcImpl<T> where <T::Invoke as Invoke>::Context: 'static {}
9
10impl<T: WrpcView> HostContext for WrpcRpcImpl<T>
11where
12    <T::Invoke as Invoke>::Context: 'static,
13{
14    fn default(&mut self) -> wasmtime::Result<Resource<Context>> {
15        let cx = self.0.wrpc().ctx.context();
16        self.0.push_context(cx)
17    }
18
19    fn drop(&mut self, cx: Resource<Context>) -> wasmtime::Result<()> {
20        self.0.delete_context(cx)?;
21        Ok(())
22    }
23}