wasm_bridge_js/
caller.rs

1use std::ops::{Deref, DerefMut};
2
3use crate::*;
4
5#[derive(Debug)]
6pub struct Caller<T> {
7    store: Store<T>,
8}
9
10impl<T> Caller<T> {
11    pub(crate) fn new(handle: DataHandle<T>) -> Self {
12        Self {
13            store: Store::from_handle(handle),
14        }
15    }
16
17    pub fn data(&self) -> impl Deref<Target = T> + '_ {
18        self.store.data()
19    }
20
21    pub fn data_mut(&mut self) -> impl DerefMut<Target = T> + '_ {
22        self.store.data_mut()
23    }
24}
25
26impl<T> Clone for Caller<T> {
27    fn clone(&self) -> Self {
28        Self {
29            store: self.store.clone(),
30        }
31    }
32}
33
34impl<T> AsContext for Caller<T> {
35    type Data = T;
36
37    fn as_context(&self) -> &Store<Self::Data> {
38        &self.store
39    }
40}
41
42impl<T> AsContextMut for Caller<T> {
43    fn as_context_mut(&mut self) -> &mut Store<Self::Data> {
44        &mut self.store
45    }
46}