@@ -21,14 +21,6 @@ pub trait Factor: Any + Sized {
21
21
Ok ( ( ) )
22
22
}
23
23
24
- fn module_init < Factors : SpinFactors > (
25
- & mut self ,
26
- mut ctx : ModuleInitContext < Factors , Self > ,
27
- ) -> Result < ( ) > {
28
- _ = & mut ctx;
29
- Ok ( ( ) )
30
- }
31
-
32
24
fn validate_app ( & self , app : & App ) -> Result < ( ) > {
33
25
_ = app;
34
26
Ok ( ( ) )
@@ -38,24 +30,32 @@ pub trait Factor: Any + Sized {
38
30
type GetDataFn < Factors , Fact > =
39
31
fn ( & mut <Factors as SpinFactors >:: InstanceState ) -> & mut <Fact as Factor >:: InstanceState ;
40
32
41
- pub struct FactorInitContext < ' a , Factors : SpinFactors , Fact : Factor , Linker > {
42
- linker : & ' a mut Linker ,
33
+ pub struct InitContext < ' a , Factors : SpinFactors , Fact : Factor > {
34
+ linker : Option < & ' a mut Linker < Factors > > ,
35
+ module_linker : Option < & ' a mut ModuleLinker < Factors > > ,
43
36
get_data : GetDataFn < Factors , Fact > ,
44
37
}
45
38
46
- pub type InitContext < ' a , Factors , Fact > = FactorInitContext < ' a , Factors , Fact , Linker < Factors > > ;
47
-
48
- pub type ModuleInitContext < ' a , Factors , Fact > =
49
- FactorInitContext < ' a , Factors , Fact , ModuleLinker < Factors > > ;
50
-
51
- impl < ' a , Factors : SpinFactors , Fact : Factor , Linker > FactorInitContext < ' a , Factors , Fact , Linker > {
39
+ impl < ' a , Factors : SpinFactors , Fact : Factor > InitContext < ' a , Factors , Fact > {
52
40
#[ doc( hidden) ]
53
- pub fn new ( linker : & ' a mut Linker , get_data : GetDataFn < Factors , Fact > ) -> Self {
54
- Self { linker, get_data }
41
+ pub fn new (
42
+ linker : Option < & ' a mut Linker < Factors > > ,
43
+ module_linker : Option < & ' a mut ModuleLinker < Factors > > ,
44
+ get_data : GetDataFn < Factors , Fact > ,
45
+ ) -> Self {
46
+ Self {
47
+ linker,
48
+ module_linker,
49
+ get_data,
50
+ }
51
+ }
52
+
53
+ pub fn linker ( & mut self ) -> Option < & mut Linker < Factors > > {
54
+ self . linker . as_deref_mut ( )
55
55
}
56
56
57
- pub fn linker ( & mut self ) -> & mut Linker {
58
- self . linker
57
+ pub fn module_linker ( & mut self ) -> Option < & mut ModuleLinker < Factors > > {
58
+ self . module_linker . as_deref_mut ( )
59
59
}
60
60
61
61
pub fn get_data_fn ( & self ) -> GetDataFn < Factors , Fact > {
@@ -65,12 +65,31 @@ impl<'a, Factors: SpinFactors, Fact: Factor, Linker> FactorInitContext<'a, Facto
65
65
pub fn link_bindings (
66
66
& mut self ,
67
67
add_to_linker : impl Fn (
68
- & mut Linker ,
68
+ & mut Linker < Factors > ,
69
69
fn ( & mut Factors :: InstanceState ) -> & mut Fact :: InstanceState ,
70
70
) -> Result < ( ) > ,
71
71
) -> Result < ( ) >
72
72
where {
73
- add_to_linker ( self . linker , self . get_data )
73
+ if let Some ( linker) = self . linker . as_deref_mut ( ) {
74
+ add_to_linker ( linker, self . get_data )
75
+ } else {
76
+ Ok ( ( ) )
77
+ }
78
+ }
79
+
80
+ pub fn link_module_bindings (
81
+ & mut self ,
82
+ add_to_linker : impl Fn (
83
+ & mut ModuleLinker < Factors > ,
84
+ fn ( & mut Factors :: InstanceState ) -> & mut Fact :: InstanceState ,
85
+ ) -> Result < ( ) > ,
86
+ ) -> Result < ( ) >
87
+ where {
88
+ if let Some ( linker) = self . module_linker . as_deref_mut ( ) {
89
+ add_to_linker ( linker, self . get_data )
90
+ } else {
91
+ Ok ( ( ) )
92
+ }
74
93
}
75
94
}
76
95
0 commit comments