1use std::any::TypeId;
7use std::sync::Arc;
8
9use crate::component::BoxFuture;
10use crate::scope::Scope;
11use crate::store::{Store, TraitImplEntry};
12use crate::{RIE, App, CancellationToken};
13
14#[linkme::distributed_slice]
16pub static COMPONENT_REGISTRY: [ComponentMeta] = [..];
17
18pub struct ComponentMeta {
24 pub type_id: fn() -> TypeId,
28
29 pub name: &'static str,
31
32 pub dep_type_ids: &'static [fn() -> TypeId],
34
35 pub factory: fn(&Store) -> Box<dyn std::any::Any + Send + Sync>,
37
38 pub scope: Scope,
40
41 pub impl_traits: &'static [fn() -> TypeId],
43
44 pub trait_impls: &'static [TraitImplEntry],
46
47 pub init_sort_fn: fn() -> i32,
51
52 pub init_fn: fn(&Arc<App>) -> RIE<()>,
54
55 pub async_init_fn: fn(&Arc<App>) -> BoxFuture<RIE<()>>,
57
58 pub async_run_fn: fn(&Arc<App>, CancellationToken) -> BoxFuture<RIE<()>>,
60
61 pub shutdown_fn: fn(&Store),
63}
64
65impl ComponentMeta {
66 pub fn build(&self, store: &Store) -> Box<dyn std::any::Any + Send + Sync> {
68 (self.factory)(store)
69 }
70
71 pub fn type_id(&self) -> TypeId {
73 (self.type_id)()
74 }
75
76 pub fn dep_ids(&self) -> Vec<TypeId> {
78 self.dep_type_ids.iter().map(|f| f()).collect()
79 }
80}