wasm_bridge_js/
context.rs

1use crate::Store;
2
3pub trait AsContext {
4    type Data;
5
6    fn as_context(&self) -> &Store<Self::Data>;
7}
8
9impl<T> AsContext for Store<T> {
10    type Data = T;
11
12    fn as_context(&self) -> &Store<Self::Data> {
13        self
14    }
15}
16
17impl<'a, T: AsContext> AsContext for &'a T {
18    type Data = T::Data;
19
20    fn as_context(&self) -> &Store<Self::Data> {
21        T::as_context(*self)
22    }
23}
24
25impl<'a, T: AsContext> AsContext for &'a mut T {
26    type Data = T::Data;
27
28    fn as_context(&self) -> &Store<Self::Data> {
29        T::as_context(*self)
30    }
31}
32
33pub trait AsContextMut: AsContext {
34    fn as_context_mut(&mut self) -> &mut Store<Self::Data>;
35}
36
37impl<T> AsContextMut for Store<T> {
38    fn as_context_mut(&mut self) -> &mut Store<Self::Data> {
39        self
40    }
41}
42
43impl<'a, T: AsContextMut> AsContextMut for &'a mut T {
44    fn as_context_mut(&mut self) -> &mut Store<Self::Data> {
45        T::as_context_mut(*self)
46    }
47}