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