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!(Store @derives derive_more::From, Debug; @path store);
57
58impl BackendStore {
59 #[inline]
60 pub(crate) fn engine(&self) -> &Engine {
61 match_rt!(on self => s {
62 s.engine()
63 })
64 }
65
66 #[inline]
67 pub(crate) fn engine_mut(&mut self) -> &mut Engine {
68 match_rt!(on self => s {
69 s.engine_mut()
70 })
71 }
72}
73
74impl AsEngineRef for BackendStore {
75 #[inline]
76 fn as_engine_ref(&self) -> crate::EngineRef<'_> {
77 match_rt!(on self => s {
78 s.as_engine_ref()
79 })
80 }
81}