Struct sai::System [−][src]
pub struct System<T> where
T: ComponentRegistry, { pub entrypoint: Option<TypeId>, // some fields omitted }
Expand description
A system is a collection of components + the ability to control the lifecycle of components in a way meeting the dependency requirement of components, e.g. start/stop them.
// Assume a RootRegistry is defined here use sai::{System, Component, component_registry}; #[derive(Component)] struct Foo { } component_registry!(RootRegistry, [Foo]); #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { let mut system : System<RootRegistry> = System::new(); println!("System starting up..."); system.start().await; println!("System started."); // Waiting for Ctrl-c // signal::ctrl_c().await?; println!("System shutting down..."); system.stop().await; println!("System shutted down."); Ok(()) }
Fields
entrypoint: Option<TypeId>
If this is set, then the system will only start components that can be reached by this entrypoint.
Implementations
Create a new system with a Component Registry
Example
use sai::{component_registry, System}; component_registry!(RootRegistry, [ component1, component2 ]); let system: System<RootRegistry> = System::new();
Similar to System::new() but allow you to specified an entrypoint for the system. If an entrypoint is specified, it will become the topology root of component tree.
Create & start all components in the registry in a topological order.
The topological order is automatically derived by system from analysing #[injected]
macro attributes in component definitons.
The entrypoints will be automatically detected unless specifically specified.
following the example above:
system.start().await;
Stop and drop all components in a topological order in reverse to startup. A typical example used with tokio signal:
use tokio::signal; ... // Waiting for Ctrl-c signal::ctrl_c().await?; println!("System shutting down..."); system.stop().await; println!("System shutted down.");
Auto Trait Implementations
impl<T> !RefUnwindSafe for System<T>
impl<T> !UnwindSafe for System<T>