@@ -5,27 +5,30 @@ use wasmer::{
5
5
imports,
6
6
vm:: { self , MemoryError , MemoryStyle , TableStyle , VMMemoryDefinition , VMTableDefinition } ,
7
7
wat2wasm, Instance , Memory , MemoryType , Module , Pages , Store , TableType , Target ,
8
- Tunables as BaseTunables ,
8
+ Tunables as ReferenceTunables ,
9
9
} ;
10
10
use wasmer_compiler_cranelift:: Cranelift ;
11
11
use wasmer_engine:: Tunables ;
12
12
use wasmer_engine_jit:: JIT ;
13
13
14
- /// A custom tunables that allows you to set a memory limit
15
- struct LimitingTunables {
14
+ /// A custom tunables that allows you to set a memory limit.
15
+ ///
16
+ /// After adjusting the memory limits, it delegates all other logic
17
+ /// to the base tunables.
18
+ struct LimitingTunables < T : Tunables > {
16
19
/// The maxium a linear memory is allowed to be (in Wasm pages, 65 KiB each).
17
20
/// Since Wasmer ensures there is only none or one memory, this is practically
18
21
/// an upper limit for the guest memory.
19
22
max_memory : Pages ,
20
23
/// The base implementation we delegate all the logic to
21
- base : BaseTunables ,
24
+ base : T ,
22
25
}
23
26
24
- impl LimitingTunables {
25
- pub fn for_target ( target : & Target , limit : Pages ) -> Self {
27
+ impl < T : Tunables > LimitingTunables < T > {
28
+ pub fn new ( base : T , limit : Pages ) -> Self {
26
29
Self {
27
30
max_memory : limit,
28
- base : BaseTunables :: for_target ( target ) ,
31
+ base,
29
32
}
30
33
}
31
34
@@ -52,7 +55,7 @@ impl LimitingTunables {
52
55
}
53
56
}
54
57
55
- impl Tunables for LimitingTunables {
58
+ impl < T : Tunables > Tunables for LimitingTunables < T > {
56
59
/// Construct a `MemoryStyle` for the provided `MemoryType`
57
60
///
58
61
/// Delegated to base.
@@ -132,8 +135,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
132
135
133
136
// Here is where the fun begins
134
137
135
- let target = Target :: default ( ) ; // TODO: should this use engine.target(), which is private?
136
- let tunables = LimitingTunables :: for_target ( & target , Pages ( 24 ) ) ;
138
+ let base = ReferenceTunables :: for_target ( & Target :: default ( ) ) ;
139
+ let tunables = LimitingTunables :: new ( base , Pages ( 24 ) ) ;
137
140
138
141
// Create a store, that holds the engine and our custom tunables
139
142
let store = Store :: new_with_tunables ( & engine, tunables) ;
0 commit comments