wrpc_runtime_wasmtime/rpc/host/
context.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use wasmtime::component::Resource;
use wrpc_transport::Invoke;

use crate::bindings::rpc::context::{Context, Host, HostContext};
use crate::rpc::WrpcRpcImpl;
use crate::{WrpcView, WrpcViewExt as _};

impl<T: WrpcView> Host for WrpcRpcImpl<T> where <T::Invoke as Invoke>::Context: 'static {}

impl<T: WrpcView> HostContext for WrpcRpcImpl<T>
where
    <T::Invoke as Invoke>::Context: 'static,
{
    fn default(&mut self) -> wasmtime::Result<Resource<Context>> {
        let cx = self.0.context();
        self.0.push_context(cx)
    }

    fn drop(&mut self, cx: Resource<Context>) -> wasmtime::Result<()> {
        self.0.delete_context(cx)?;
        Ok(())
    }
}