verdure_ioc/
component.rs

1pub mod factory;
2
3use std::any::{Any, TypeId};
4use std::collections::HashMap;
5use std::sync::Arc;
6use verdure_core::error::component::ComponentError;
7
8pub type ComponentInstance = Arc<dyn Any + Send + Sync>;
9
10pub enum ComponentScope {
11    Singleton,
12    Prototype,
13}
14
15#[derive(Debug)]
16pub struct ComponentDefinition {
17    pub type_id: fn() -> TypeId,
18    pub type_name: &'static str,
19    pub scope: fn() -> ComponentScope,
20    pub dependencies: fn() -> Vec<TypeId>,
21    pub creator: fn(deps: HashMap<TypeId, ComponentInstance>) -> Result<ComponentInstance, ComponentError>,
22}
23
24inventory::collect!(ComponentDefinition);
25
26pub trait ComponentInitializer: Sized {
27    type Dependencies;
28    fn __new(deps: Self::Dependencies) -> Self;
29    fn __scope() -> ComponentScope;
30}