linera_wasmer/
extern_ref.rs1use std::any::Any;
2
3use crate::store::{AsStoreMut, AsStoreRef};
4
5#[cfg(feature = "js")]
6use crate::js::extern_ref as extern_ref_imp;
7#[cfg(feature = "jsc")]
8use crate::jsc::extern_ref as extern_ref_imp;
9#[cfg(feature = "sys")]
10use crate::sys::extern_ref as extern_ref_imp;
11use crate::vm::VMExternRef;
12
13#[derive(Debug, Clone)]
14#[repr(transparent)]
15pub struct ExternRef(pub(crate) extern_ref_imp::ExternRef);
17
18impl ExternRef {
19 pub fn new<T>(store: &mut impl AsStoreMut, value: T) -> Self
21 where
22 T: Any + Send + Sync + 'static + Sized,
23 {
24 Self(extern_ref_imp::ExternRef::new(store, value))
25 }
26
27 pub fn downcast<'a, T>(&self, store: &'a impl AsStoreRef) -> Option<&'a T>
29 where
30 T: Any + Send + Sync + 'static + Sized,
31 {
32 self.0.downcast(store)
33 }
34
35 pub(crate) fn vm_externref(&self) -> VMExternRef {
36 self.0.vm_externref()
37 }
38
39 pub(crate) unsafe fn from_vm_externref(
40 store: &mut impl AsStoreMut,
41 vm_externref: VMExternRef,
42 ) -> Self {
43 Self(extern_ref_imp::ExternRef::from_vm_externref(
44 store,
45 vm_externref,
46 ))
47 }
48
49 pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool {
57 self.0.is_from_store(store)
58 }
59}