@@ -73,29 +73,39 @@ point for `spin-factors` (note that some type details are elided for clarity):
73
73
74
74
``` rust
75
75
pub trait Factor {
76
- // InstancePreparer represents a type that can prepare this Factor's InstanceState.
77
- type InstancePreparer : InstancePreparer <Self >;
78
- // InstanceState represents this Factor's per-instance state.
76
+ /// App configuration for this factor.
77
+ ///
78
+ /// See [`Factor::configure_app`].
79
+ type AppConfig ;
80
+
81
+ /// The [`FactorInstancePreparer`] for this factor.
82
+ type InstancePreparer : FactorInstancePreparer <Self >;
83
+
84
+ /// The per-instance state for this factor, constructed by a
85
+ /// [`FactorInstancePreparer`] and available to any host-provided imports
86
+ /// defined by this factor.
79
87
type InstanceState ;
80
88
81
- // Init is the runtime startup lifecycle hook.
82
- //
83
- // The `InitContext` type here gives the factor the ability to update global
84
- // engine configuration, most notably the `Linker`. This takes the place of
85
- // `HostComponent::add_to_linker`.
86
- fn init (& mut self , ctx : InitContext ) -> Result <()> {
89
+ /// Initializes this Factor for a runtime. This will be called at most once,
90
+ /// before any call to [`FactorInstancePreparer::new`]
91
+ fn init <Factors : SpinFactors >(& mut self , mut ctx : InitContext <Factors , Self >) -> Result <()> {
92
+ _ = & mut ctx ;
87
93
Ok (())
88
94
}
89
95
90
- // Validate app is the application initialization hook.
91
- //
92
- // This takes the place of `DynamicHostComponent::validate_app`.
93
- fn validate_app (& self , app : & App ) -> Result <()> {
94
- Ok (())
95
- }
96
+ /// Performs factor-specific validation and configuration for the given
97
+ /// [`App`] and [`RuntimeConfig`]. A runtime may - but is not required to -
98
+ /// reuse the returned config across multiple instances. Note that this may
99
+ /// be called without any call to `init` in cases where only validation is
100
+ /// needed.
101
+ fn configure_app <Factors : SpinFactors >(
102
+ & self ,
103
+ app : & App ,
104
+ _ctx : ConfigureAppContext <Factors >,
105
+ );
96
106
}
97
107
98
- pub trait InstancePreparer <Factor > {
108
+ pub trait FactorInstancePreparer <Factor > {
99
109
// This is the component pre-instantiation hook.
100
110
//
101
111
// The `PrepareContext` type gives access to information about the Spin app
0 commit comments