@@ -2,13 +2,13 @@ use std::any::Any;
2
2
3
3
use anyhow:: Context ;
4
4
5
- use crate :: { App , FactorInstancePreparer , Linker , ModuleLinker , RuntimeConfig , SpinFactors } ;
5
+ use crate :: { App , FactorInstancePreparer , Linker , ModuleLinker , RuntimeConfig , RuntimeFactors } ;
6
6
7
7
pub trait Factor : Any + Sized {
8
- /// Per-app configuration for this factor.
8
+ /// Per-app state for this factor.
9
9
///
10
10
/// See [`Factor::configure_app`].
11
- type AppConfig : Default ;
11
+ type AppState : Default ;
12
12
13
13
/// The [`FactorInstancePreparer`] for this factor.
14
14
type InstancePreparer : FactorInstancePreparer < Self > ;
@@ -20,10 +20,7 @@ pub trait Factor: Any + Sized {
20
20
21
21
/// Initializes this Factor for a runtime. This will be called at most once,
22
22
/// before any call to [`FactorInstancePreparer::new`]
23
- fn init < Factors : SpinFactors > (
24
- & mut self ,
25
- mut ctx : InitContext < Factors , Self > ,
26
- ) -> anyhow:: Result < ( ) > {
23
+ fn init < T : RuntimeFactors > ( & mut self , mut ctx : InitContext < T , Self > ) -> anyhow:: Result < ( ) > {
27
24
// TODO: Should `ctx` always be immut? Rename this param/type?
28
25
_ = & mut ctx;
29
26
Ok ( ( ) )
@@ -33,33 +30,33 @@ pub trait Factor: Any + Sized {
33
30
/// [`App`]. A runtime may - but is not required to - reuse the returned
34
31
/// config across multiple instances. Note that this may be called without
35
32
/// any call to `init` in cases where only validation is needed.
36
- fn configure_app < Factors : SpinFactors > (
33
+ fn configure_app < T : RuntimeFactors > (
37
34
& self ,
38
- ctx : ConfigureAppContext < Factors > ,
35
+ ctx : ConfigureAppContext < T > ,
39
36
_runtime_config : & mut impl RuntimeConfig ,
40
- ) -> anyhow:: Result < Self :: AppConfig > {
37
+ ) -> anyhow:: Result < Self :: AppState > {
41
38
_ = ctx;
42
39
Ok ( Default :: default ( ) )
43
40
}
44
41
}
45
42
46
- pub ( crate ) type GetDataFn < Factors , Fact > =
47
- fn ( & mut <Factors as SpinFactors >:: InstanceState ) -> & mut <Fact as Factor >:: InstanceState ;
43
+ pub ( crate ) type GetDataFn < Facts , Fact > =
44
+ fn ( & mut <Facts as RuntimeFactors >:: InstanceState ) -> & mut <Fact as Factor >:: InstanceState ;
48
45
49
46
/// An InitContext is passed to [`Factor::init`], giving access to the global
50
47
/// common [`wasmtime::component::Linker`].
51
- pub struct InitContext < ' a , Factors : SpinFactors , T : Factor > {
52
- pub ( crate ) linker : Option < & ' a mut Linker < Factors > > ,
53
- pub ( crate ) module_linker : Option < & ' a mut ModuleLinker < Factors > > ,
54
- pub ( crate ) get_data : GetDataFn < Factors , T > ,
48
+ pub struct InitContext < ' a , T : RuntimeFactors , F : Factor > {
49
+ pub ( crate ) linker : Option < & ' a mut Linker < T > > ,
50
+ pub ( crate ) module_linker : Option < & ' a mut ModuleLinker < T > > ,
51
+ pub ( crate ) get_data : GetDataFn < T , F > ,
55
52
}
56
53
57
- impl < ' a , Factors : SpinFactors , T : Factor > InitContext < ' a , Factors , T > {
54
+ impl < ' a , T : RuntimeFactors , F : Factor > InitContext < ' a , T , F > {
58
55
#[ doc( hidden) ]
59
56
pub fn new (
60
- linker : Option < & ' a mut Linker < Factors > > ,
61
- module_linker : Option < & ' a mut ModuleLinker < Factors > > ,
62
- get_data : GetDataFn < Factors , T > ,
57
+ linker : Option < & ' a mut Linker < T > > ,
58
+ module_linker : Option < & ' a mut ModuleLinker < T > > ,
59
+ get_data : GetDataFn < T , F > ,
63
60
) -> Self {
64
61
Self {
65
62
linker,
@@ -68,23 +65,23 @@ impl<'a, Factors: SpinFactors, T: Factor> InitContext<'a, Factors, T> {
68
65
}
69
66
}
70
67
71
- pub fn linker ( & mut self ) -> Option < & mut Linker < Factors > > {
68
+ pub fn linker ( & mut self ) -> Option < & mut Linker < T > > {
72
69
self . linker . as_deref_mut ( )
73
70
}
74
71
75
- pub fn module_linker ( & mut self ) -> Option < & mut ModuleLinker < Factors > > {
72
+ pub fn module_linker ( & mut self ) -> Option < & mut ModuleLinker < T > > {
76
73
self . module_linker . as_deref_mut ( )
77
74
}
78
75
79
- pub fn get_data_fn ( & self ) -> GetDataFn < Factors , T > {
76
+ pub fn get_data_fn ( & self ) -> GetDataFn < T , F > {
80
77
self . get_data
81
78
}
82
79
83
80
pub fn link_bindings (
84
81
& mut self ,
85
82
add_to_linker : impl Fn (
86
- & mut Linker < Factors > ,
87
- fn ( & mut Factors :: InstanceState ) -> & mut T :: InstanceState ,
83
+ & mut Linker < T > ,
84
+ fn ( & mut T :: InstanceState ) -> & mut F :: InstanceState ,
88
85
) -> anyhow:: Result < ( ) > ,
89
86
) -> anyhow:: Result < ( ) >
90
87
where {
@@ -98,8 +95,8 @@ where {
98
95
pub fn link_module_bindings (
99
96
& mut self ,
100
97
add_to_linker : impl Fn (
101
- & mut ModuleLinker < Factors > ,
102
- fn ( & mut Factors :: InstanceState ) -> & mut T :: InstanceState ,
98
+ & mut ModuleLinker < T > ,
99
+ fn ( & mut T :: InstanceState ) -> & mut F :: InstanceState ,
103
100
) -> anyhow:: Result < ( ) > ,
104
101
) -> anyhow:: Result < ( ) >
105
102
where {
@@ -111,42 +108,42 @@ where {
111
108
}
112
109
}
113
110
114
- pub struct ConfigureAppContext < ' a , Factors : SpinFactors > {
111
+ pub struct ConfigureAppContext < ' a , T : RuntimeFactors > {
115
112
pub ( crate ) app : & ' a App ,
116
- pub ( crate ) app_configs : & ' a Factors :: AppConfigs ,
113
+ pub ( crate ) app_configs : & ' a T :: AppState ,
117
114
}
118
115
119
- impl < ' a , Factors : SpinFactors > ConfigureAppContext < ' a , Factors > {
116
+ impl < ' a , T : RuntimeFactors > ConfigureAppContext < ' a , T > {
120
117
#[ doc( hidden) ]
121
- pub fn new ( app : & ' a App , app_configs : & ' a Factors :: AppConfigs ) -> Self {
118
+ pub fn new ( app : & ' a App , app_configs : & ' a T :: AppState ) -> Self {
122
119
Self { app, app_configs }
123
120
}
124
121
125
122
pub fn app ( & self ) -> & App {
126
123
self . app
127
124
}
128
125
129
- pub fn app_config < T : Factor > ( & self ) -> crate :: Result < & T :: AppConfig > {
130
- Factors :: app_config :: < T > ( self . app_configs ) . context ( "no such factor" )
126
+ pub fn app_config < F : Factor > ( & self ) -> crate :: Result < & F :: AppState > {
127
+ T :: app_config :: < F > ( self . app_configs ) . context ( "no such factor" )
131
128
}
132
129
}
133
130
134
- pub struct ConfiguredApp < Factors : SpinFactors > {
131
+ pub struct ConfiguredApp < T : RuntimeFactors > {
135
132
app : App ,
136
- app_configs : Factors :: AppConfigs ,
133
+ app_configs : T :: AppState ,
137
134
}
138
135
139
- impl < Factors : SpinFactors > ConfiguredApp < Factors > {
136
+ impl < T : RuntimeFactors > ConfiguredApp < T > {
140
137
#[ doc( hidden) ]
141
- pub fn new ( app : App , app_configs : Factors :: AppConfigs ) -> Self {
138
+ pub fn new ( app : App , app_configs : T :: AppState ) -> Self {
142
139
Self { app, app_configs }
143
140
}
144
141
145
142
pub fn app ( & self ) -> & App {
146
143
& self . app
147
144
}
148
145
149
- pub fn app_config < T : Factor > ( & self ) -> crate :: Result < & T :: AppConfig > {
150
- Factors :: app_config :: < T > ( & self . app_configs ) . context ( "no such factor" )
146
+ pub fn app_config < F : Factor > ( & self ) -> crate :: Result < & F :: AppState > {
147
+ T :: app_config :: < F > ( & self . app_configs ) . context ( "no such factor" )
151
148
}
152
149
}
0 commit comments