[−][src]Trait sai::Component
A Component is a bunch of business-logic behaviors + startup logic.
Normally, you won't need to manually implement this.
Defining components with no explict startup / shutdown logic
use sai::{Component, Injected}; #[derive(Component)] struct Bar {} #[derive(Component)] struct Foo { #[injected] bar: Injected<Bar> }
In above example, Foo
and Bar
are both component. Foo depends on Bar, the dependency is
defined via the #[injected]
attributes.
Note: a dependency injected by Sai has to be wrapped by Injected
struct.
Component with explict startup / shutdown logic
use sai::{Component, ComponentLifecycle, async_trait}; #[derive(Component)] #[lifecycle] struct Foo { internal: Option<u32> } #[async_trait] impl ComponentLifecycle for Foo { async fn start(&mut self) { self.internal = Some(42); } async fn stop(&mut self) { // Any shutdown logic } }
Required methods
fn build(registry: &ComponentRepository) -> Self where
Self: Sized,
Self: Sized,
fn meta() -> ComponentMeta<Box<Self>> where
Self: Sized,
Self: Sized,