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