@@ -8,12 +8,12 @@ pub use wasmtime;
8
8
pub type Error = wasmtime:: Error ;
9
9
pub type Result < T , E = Error > = std:: result:: Result < T , E > ;
10
10
11
- pub type Linker < Factors > = wasmtime:: component:: Linker < <Factors as SpinFactors >:: Data > ;
12
- pub type ModuleLinker < Factors > = wasmtime:: Linker < <Factors as SpinFactors >:: Data > ;
11
+ pub type Linker < Factors > = wasmtime:: component:: Linker < <Factors as SpinFactors >:: InstanceState > ;
12
+ pub type ModuleLinker < Factors > = wasmtime:: Linker < <Factors as SpinFactors >:: InstanceState > ;
13
13
14
14
pub trait Factor : Any + Sized {
15
- type Builder : FactorBuilder < Self > ;
16
- type Data ;
15
+ type InstancePreparer : FactorInstancePreparer < Self > ;
16
+ type InstanceState ;
17
17
18
18
/// Initializes this Factor for a runtime. This will be called exactly once
19
19
fn init < Factors : SpinFactors > ( & mut self , mut ctx : InitContext < Factors , Self > ) -> Result < ( ) > {
@@ -37,7 +37,7 @@ pub trait Factor: Any + Sized {
37
37
38
38
pub struct FactorInitContext < ' a , Factors : SpinFactors , Fact : Factor , Linker > {
39
39
linker : & ' a mut Linker ,
40
- get_data : fn ( & mut Factors :: Data ) -> & mut Fact :: Data ,
40
+ get_data : fn ( & mut Factors :: InstanceState ) -> & mut Fact :: InstanceState ,
41
41
}
42
42
43
43
pub type InitContext < ' a , Factors , Fact > = FactorInitContext < ' a , Factors , Fact , Linker < Factors > > ;
@@ -49,7 +49,7 @@ impl<'a, Factors: SpinFactors, Fact: Factor, Linker> FactorInitContext<'a, Facto
49
49
#[ doc( hidden) ]
50
50
pub fn new (
51
51
linker : & ' a mut Linker ,
52
- get_data : fn ( & mut Factors :: Data ) -> & mut Fact :: Data ,
52
+ get_data : fn ( & mut Factors :: InstanceState ) -> & mut Fact :: InstanceState ,
53
53
) -> Self {
54
54
Self { linker, get_data }
55
55
}
@@ -60,15 +60,18 @@ impl<'a, Factors: SpinFactors, Fact: Factor, Linker> FactorInitContext<'a, Facto
60
60
61
61
pub fn link_bindings (
62
62
& mut self ,
63
- add_to_linker : impl Fn ( & mut Linker , fn ( & mut Factors :: Data ) -> & mut Fact :: Data ) -> Result < ( ) > ,
63
+ add_to_linker : impl Fn (
64
+ & mut Linker ,
65
+ fn ( & mut Factors :: InstanceState ) -> & mut Fact :: InstanceState ,
66
+ ) -> Result < ( ) > ,
64
67
) -> Result < ( ) >
65
68
where {
66
69
add_to_linker ( self . linker , self . get_data )
67
70
}
68
71
}
69
72
70
73
impl < ' a , Factors : SpinFactors > PrepareContext < ' a , Factors > {
71
- pub fn builder_mut < T : Factor > ( & mut self ) -> Result < & mut T :: Builder > {
74
+ pub fn builder_mut < T : Factor > ( & mut self ) -> Result < & mut T :: InstancePreparer > {
72
75
let err_msg = match Factors :: builder_mut :: < T > ( self . builders ) {
73
76
Some ( Some ( builder) ) => return Ok ( builder) ,
74
77
Some ( None ) => "builder not yet prepared" ,
@@ -84,23 +87,24 @@ impl<'a, Factors: SpinFactors> PrepareContext<'a, Factors> {
84
87
/// Implemented by `#[derive(SpinFactors)]`
85
88
pub trait SpinFactors : Sized {
86
89
type Builders ;
87
- type Data : Send + ' static ;
90
+ type InstanceState : Send + ' static ;
88
91
89
92
#[ doc( hidden) ]
90
93
unsafe fn factor_builder_offset < T : Factor > ( ) -> Option < usize > ;
91
94
92
95
#[ doc( hidden) ]
93
96
unsafe fn factor_data_offset < T : Factor > ( ) -> Option < usize > ;
94
97
95
- fn data_getter < T : Factor > ( ) -> Option < Getter < Self :: Data , T :: Data > > {
98
+ fn data_getter < T : Factor > ( ) -> Option < Getter < Self :: InstanceState , T :: InstanceState > > {
96
99
let offset = unsafe { Self :: factor_data_offset :: < T > ( ) ? } ;
97
100
Some ( Getter {
98
101
offset,
99
102
_phantom : PhantomData ,
100
103
} )
101
104
}
102
105
103
- fn data_getter2 < T1 : Factor , T2 : Factor > ( ) -> Option < Getter2 < Self :: Data , T1 :: Data , T2 :: Data > > {
106
+ fn data_getter2 < T1 : Factor , T2 : Factor > (
107
+ ) -> Option < Getter2 < Self :: InstanceState , T1 :: InstanceState , T2 :: InstanceState > > {
104
108
let offset1 = unsafe { Self :: factor_data_offset :: < T1 > ( ) ? } ;
105
109
let offset2 = unsafe { Self :: factor_data_offset :: < T2 > ( ) ? } ;
106
110
assert_ne ! (
@@ -114,11 +118,13 @@ pub trait SpinFactors: Sized {
114
118
} )
115
119
}
116
120
117
- fn builder_mut < T : Factor > ( builders : & mut Self :: Builders ) -> Option < Option < & mut T :: Builder > > {
121
+ fn builder_mut < T : Factor > (
122
+ builders : & mut Self :: Builders ,
123
+ ) -> Option < Option < & mut T :: InstancePreparer > > {
118
124
unsafe {
119
125
let offset = Self :: factor_builder_offset :: < T > ( ) ?;
120
126
let ptr = builders as * mut Self :: Builders ;
121
- let opt = & mut * ptr. add ( offset) . cast :: < Option < T :: Builder > > ( ) ;
127
+ let opt = & mut * ptr. add ( offset) . cast :: < Option < T :: InstancePreparer > > ( ) ;
122
128
Some ( opt. as_mut ( ) )
123
129
}
124
130
}
@@ -174,10 +180,10 @@ impl<T, U, V> Clone for Getter2<T, U, V> {
174
180
}
175
181
impl < T , U , V > Copy for Getter2 < T , U , V > { }
176
182
177
- pub trait FactorBuilder < T : Factor > : Sized {
178
- fn prepare < Factors : SpinFactors > ( _factor : & T , _ctx : PrepareContext < Factors > ) -> Result < Self > ;
183
+ pub trait FactorInstancePreparer < T : Factor > : Sized {
184
+ fn new < Factors : SpinFactors > ( _factor : & T , _ctx : PrepareContext < Factors > ) -> Result < Self > ;
179
185
180
- fn build ( self ) -> Result < T :: Data > ;
186
+ fn prepare ( self ) -> Result < T :: InstanceState > ;
181
187
}
182
188
183
189
pub struct PrepareContext < ' a , Factors : SpinFactors > {
@@ -194,16 +200,16 @@ impl<'a, Factors: SpinFactors> PrepareContext<'a, Factors> {
194
200
195
201
pub type DefaultBuilder = ( ) ;
196
202
197
- impl < T : Factor > FactorBuilder < T > for DefaultBuilder
203
+ impl < T : Factor > FactorInstancePreparer < T > for DefaultBuilder
198
204
where
199
- T :: Data : Default ,
205
+ T :: InstanceState : Default ,
200
206
{
201
- fn prepare < Factors : SpinFactors > ( factor : & T , ctx : PrepareContext < Factors > ) -> Result < Self > {
207
+ fn new < Factors : SpinFactors > ( factor : & T , ctx : PrepareContext < Factors > ) -> Result < Self > {
202
208
( _, _) = ( factor, ctx) ;
203
209
Ok ( ( ) )
204
210
}
205
211
206
- fn build ( self ) -> Result < T :: Data > {
212
+ fn prepare ( self ) -> Result < T :: InstanceState > {
207
213
Ok ( Default :: default ( ) )
208
214
}
209
215
}
0 commit comments