wasmer/entities/external/extref/
mod.rs1use std::any::Any;
2
3use crate::StoreRef;
4use crate::entities::store::{AsStoreMut, AsStoreRef};
5use crate::vm::VMExternRef;
6
7pub(crate) mod inner;
8pub(crate) use inner::*;
9
10#[derive(Debug, Clone, derive_more::From)]
11pub struct ExternRef(pub(crate) BackendExternRef);
13
14impl ExternRef {
15 pub fn new<T>(store: &mut impl AsStoreMut, value: T) -> Self
17 where
18 T: Any + Send + Sync + 'static + Sized,
19 {
20 Self(BackendExternRef::new(store, value))
21 }
22
23 pub fn downcast<'a, T>(&self, store: &'a impl AsStoreRef) -> Option<&'a T>
25 where
26 T: Any + Send + Sync + 'static + Sized,
27 {
28 self.0.downcast(store)
29 }
30
31 pub(crate) fn vm_externref(&self) -> VMExternRef {
33 self.0.vm_externref()
34 }
35
36 pub(crate) unsafe fn from_vm_externref(
38 store: &mut impl AsStoreMut,
39 vm_externref: VMExternRef,
40 ) -> Self {
41 Self(unsafe { BackendExternRef::from_vm_externref(store, vm_externref) })
42 }
43
44 pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool {
52 self.0.is_from_store(store)
53 }
54}