1use std::any::Any;
2use wasmer_types::RawValue;
3
4use crate::store::InternalStoreHandle;
5
6#[derive(Debug)]
8pub struct VMExternObj {
9 contents: Box<dyn Any + Send + Sync + 'static>,
10}
11
12impl VMExternObj {
13 pub fn new(val: impl Any + Send + Sync + 'static) -> Self {
15 Self {
16 contents: Box::new(val),
17 }
18 }
19
20 #[allow(clippy::should_implement_trait)]
21 pub fn as_ref(&self) -> &(dyn Any + Send + Sync + 'static) {
23 &*self.contents
24 }
25}
26
27#[repr(transparent)]
29#[derive(Debug, Clone, Copy)]
30pub struct VMExternRef(pub InternalStoreHandle<VMExternObj>);
31
32impl VMExternRef {
33 pub fn into_raw(self) -> RawValue {
35 RawValue {
36 funcref: self.0.index(),
37 }
38 }
39
40 pub unsafe fn from_raw(raw: RawValue) -> Option<Self> {
45 InternalStoreHandle::from_index(raw.externref).map(Self)
46 }
47}