pub trait Factor: Any + Sized {
type RuntimeConfig;
type AppState: Sync;
type InstanceBuilder: FactorInstanceBuilder;
// Required methods
fn configure_app<T: RuntimeFactors>(
&self,
ctx: ConfigureAppContext<'_, T, Self>,
) -> Result<Self::AppState>;
fn prepare<T: RuntimeFactors>(
&self,
ctx: PrepareContext<'_, T, Self>,
) -> Result<Self::InstanceBuilder>;
// Provided method
fn init<T: Send + 'static>(
&mut self,
ctx: InitContext<'_, T, Self>,
) -> Result<()> { ... }
}
Expand description
A contained (i.e., “factored”) piece of runtime functionality.
Required Associated Types§
Sourcetype RuntimeConfig
type RuntimeConfig
The particular runtime configuration relevant to this factor.
Runtime configuration allows for user-provided customization of the factor’s behavior on a per-app basis.
Sourcetype AppState: Sync
type AppState: Sync
The application state of this factor.
This state may be cached by the runtime across multiple requests.
Sourcetype InstanceBuilder: FactorInstanceBuilder
type InstanceBuilder: FactorInstanceBuilder
The builder of instance state for this factor.
Required Methods§
Sourcefn configure_app<T: RuntimeFactors>(
&self,
ctx: ConfigureAppContext<'_, T, Self>,
) -> Result<Self::AppState>
fn configure_app<T: RuntimeFactors>( &self, ctx: ConfigureAppContext<'_, T, Self>, ) -> Result<Self::AppState>
Performs factor-specific validation and configuration for the given
App
.
ConfigureAppContext
gives access to:
- The
spin_app::App
- This factors’s
RuntimeConfig
- The
AppState
for any factors configured before this one
A runtime may - but is not required to - reuse the returned config across multiple instances. Because this method may be called per-instantiation, it should avoid any blocking operations that could unnecessarily delay execution.
This method may be called without any call to init
or prepare
in
cases where only validation is needed (e.g., spin doctor
).
Sourcefn prepare<T: RuntimeFactors>(
&self,
ctx: PrepareContext<'_, T, Self>,
) -> Result<Self::InstanceBuilder>
fn prepare<T: RuntimeFactors>( &self, ctx: PrepareContext<'_, T, Self>, ) -> Result<Self::InstanceBuilder>
Creates a new FactorInstanceBuilder
, which will later build
per-instance state for this factor.
This method is given access to the app component being instantiated and to any other factors’ instance builders that have already been prepared. As such, this is the primary place for inter-factor dependencies to be used.
Provided Methods§
Sourcefn init<T: Send + 'static>(
&mut self,
ctx: InitContext<'_, T, Self>,
) -> Result<()>
fn init<T: Send + 'static>( &mut self, ctx: InitContext<'_, T, Self>, ) -> Result<()>
Initializes this Factor
for a runtime once at runtime startup.
This will be called at most once, before any call to
Factor::prepare
. InitContext
provides access to a wasmtime
Linker
, so this is where any bindgen add_to_linker
calls go.
The type parameter T
here is the same as the wasmtime::Store
type
parameter T
, which will contain the RuntimeFactors::InstanceState
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.