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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#[cfg(not(feature = "std"))]
use crate::wasmi as e;
#[cfg(feature = "std")]
use crate::wasmtime as e;
use crate::{
derive::{self, HostCall, HostFuncType},
memory::Memory,
};
use ceres_std::Vec;
use core::ops;
pub struct Builder<T>(e::Builder<T>);
impl<T> Default for Builder<T> {
fn default() -> Self {
Self::new()
}
}
impl<T> ops::Deref for Builder<T> {
type Target = e::Builder<T>;
fn deref(&self) -> &e::Builder<T> {
&self.0
}
}
impl<T> Builder<T> {
pub fn new() -> Self {
Builder(<e::Builder<T> as derive::Builder<T>>::new())
}
pub fn add_host_func<M, F>(&mut self, module: M, field: F, f: HostFuncType<T>)
where
F: Into<Vec<u8>>,
M: Into<Vec<u8>>,
{
derive::Builder::add_host_func(&mut self.0, module, field, f);
}
pub fn add_host_parcel<M, F>(&mut self, call: HostCall<M, F, T>)
where
F: Into<Vec<u8>>,
M: Into<Vec<u8>>,
{
self.add_host_func(call.0, call.1, call.2)
}
pub fn add_host_parcels<M, F>(mut self, calls: Vec<HostCall<M, F, T>>) -> Self
where
F: Into<Vec<u8>>,
M: Into<Vec<u8>>,
{
for call in calls {
self.add_host_func(call.0, call.1, call.2)
}
self
}
pub fn add_memory<M, F>(&mut self, module: M, field: F, mem: Memory)
where
M: Into<Vec<u8>>,
F: Into<Vec<u8>>,
{
derive::Builder::add_memory(&mut self.0, module, field, mem.0);
}
}