wasmer/entities/store/
inner.rs1use crate::{
2 AsStoreMut, AsStoreRef, StoreRef,
3 entities::{
4 engine::{AsEngineRef, Engine},
5 store::{StoreMut, StoreObjects},
6 },
7 macros::backend::{gen_rt_ty, match_rt},
8};
9
10#[cfg(feature = "sys")]
11use wasmer_vm::TrapHandlerFn;
12
13pub(crate) struct StoreInner {
17 pub(crate) objects: StoreObjects,
18 pub(crate) store: BackendStore,
19 pub(crate) on_called: Option<OnCalledHandler>,
20}
21
22impl std::fmt::Debug for StoreInner {
23 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
24 f.debug_struct("StoreInner")
25 .field("objects", &self.objects)
26 .field("store", &self.store)
27 .field("on_called", &"<...>")
28 .finish()
29 }
30}
31
32impl AsStoreRef for StoreInner {
33 fn as_store_ref(&self) -> StoreRef<'_> {
34 StoreRef { inner: self }
35 }
36}
37impl AsStoreMut for StoreInner {
38 fn as_store_mut(&mut self) -> StoreMut<'_> {
39 StoreMut { inner: self }
40 }
41
42 fn objects_mut(&mut self) -> &mut StoreObjects {
43 &mut self.objects
44 }
45}
46
47pub type OnCalledHandler = Box<
50 dyn FnOnce(
51 StoreMut<'_>,
52 )
53 -> Result<wasmer_types::OnCalledAction, Box<dyn std::error::Error + Send + Sync>>,
54>;
55
56gen_rt_ty! {
57 #[derive(derive_more::From, Debug)]
58 pub BackendStore(entities::store::Store);
59}
60
61impl BackendStore {
62 #[inline]
63 pub(crate) fn engine(&self) -> &Engine {
64 match_rt!(on self => s {
65 s.engine()
66 })
67 }
68
69 #[inline]
70 pub(crate) fn engine_mut(&mut self) -> &mut Engine {
71 match_rt!(on self => s {
72 s.engine_mut()
73 })
74 }
75}
76
77impl AsEngineRef for BackendStore {
78 #[inline]
79 fn as_engine_ref(&self) -> crate::EngineRef<'_> {
80 match_rt!(on self => s {
81 s.as_engine_ref()
82 })
83 }
84}