Skip to content

Commit 52ce313

Browse files
authored
Update 0xx-spin-factors.md
1 parent 0ad7993 commit 52ce313

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

docs/content/sips/0xx-spin-factors.md

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,29 +73,39 @@ point for `spin-factors` (note that some type details are elided for clarity):
7373

7474
```rust
7575
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.
7987
type InstanceState;
8088

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;
8793
Ok(())
8894
}
8995

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+
);
96106
}
97107

98-
pub trait InstancePreparer<Factor> {
108+
pub trait FactorInstancePreparer<Factor> {
99109
// This is the component pre-instantiation hook.
100110
//
101111
// The `PrepareContext` type gives access to information about the Spin app

0 commit comments

Comments
 (0)