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
use crate::Runtime;
use std::cell::RefCell;
use std::ptr::NonNull;
use std::rc::Rc;
pub trait Marshal<T>: Sized {
fn marshal_value(self, runtime: Rc<RefCell<Runtime>>) -> T;
fn marshal_from_ptr(
ptr: NonNull<Self>,
runtime: Rc<RefCell<Runtime>>,
type_info: Option<&abi::TypeInfo>,
) -> T;
fn marshal_to_ptr(value: Self, ptr: NonNull<Self>, type_info: Option<&abi::TypeInfo>);
}
impl<T> Marshal<T> for T {
fn marshal_value(self, _runtime: Rc<RefCell<Runtime>>) -> T {
self
}
fn marshal_from_ptr(
ptr: NonNull<Self>,
_runtime: Rc<RefCell<Runtime>>,
_type_info: Option<&abi::TypeInfo>,
) -> T {
unsafe { ptr.as_ptr().read() }
}
fn marshal_to_ptr(value: T, mut ptr: NonNull<Self>, _type_info: Option<&abi::TypeInfo>) {
unsafe { *ptr.as_mut() = value };
}
}