Trait abscissa_core::component::Component [−][src]
pub trait Component<A>: AsAny + Debug + Send + Sync where
A: Application, {
fn id(&self) -> Id;
fn version(&self) -> Version;
fn after_config(&mut self, config: &A::Cfg) -> Result<(), FrameworkError> { ... }
fn dependencies(&self) -> Iter<'_, Id> { ... }
fn register_dependency(
&mut self,
handle: Handle,
dependency: &mut dyn Component<A>
) -> Result<(), FrameworkError> { ... }
fn before_shutdown(&self, kind: Shutdown) -> Result<(), FrameworkError> { ... }
}
Expand description
Application components.
Components are Abscissa’s primary extension mechanism, and are aware of the application lifecycle. They are owned by the application as boxed trait objects in a runtime type registry which is aware of a dependency ordering and can (potentially in the future) support runtime reinitialization.
During application initialization, callbacks are sent to all components
upon events like application configuration being loaded. The
register_dependency
callback is called for each dependency returned
by the dependencies
method.
Additionally, they receive a callback prior to application shutdown.
Custom Derive
The main intended way to impl this trait is by using the built-in custom derive functionality.
use abscissa_core::Component;
#[derive(Component, Debug)]
pub struct MyComponent {}
This will automatically implement the entire trait for you.
Required methods
Identifier for this component.
These are the Rust path (e.g. crate_name:foo::Foo
) by convention.
Provided methods
fn after_config(&mut self, config: &A::Cfg) -> Result<(), FrameworkError>
fn after_config(&mut self, config: &A::Cfg) -> Result<(), FrameworkError>
Lifecycle event called when application configuration should be loaded if it were possible.
fn dependencies(&self) -> Iter<'_, Id>
fn dependencies(&self) -> Iter<'_, Id>
Names of the components this component depends on.
After this app’s after_config
callback is fired, the
register_dependency
callback below will be fired for each of these.
fn register_dependency(
&mut self,
handle: Handle,
dependency: &mut dyn Component<A>
) -> Result<(), FrameworkError>
fn register_dependency(
&mut self,
handle: Handle,
dependency: &mut dyn Component<A>
) -> Result<(), FrameworkError>
Register a dependency of this component (a.k.a. “dependency injection”)
fn before_shutdown(&self, kind: Shutdown) -> Result<(), FrameworkError>
fn before_shutdown(&self, kind: Shutdown) -> Result<(), FrameworkError>
Perform any tasks which should occur before the app exits