noema 0.4.0

Noema IOC and DI framework for Rust
Documentation
use std::fmt::Display;

use std::sync::Arc;

use crate::core::{Container, Resolver};

use super::ItemSet;

/// Marker for a collection (value type + `'static` metadata).
pub trait Collection: Send + Sync + 'static {
    type Value: Clone + Eq + Display + Send + Sync + 'static;

    fn name() -> &'static str;

    fn describe() -> &'static str {
        Self::name()
    }
}

/// One member of a [`Collection`].
pub trait Item: Send + Sync {
    type CollectionType: Collection;

    fn value(&self) -> <Self::CollectionType as Collection>::Value;

    fn name(&self) -> &'static str;

    fn description(&self) -> &'static str {
        self.name()
    }
}

/// Trait object stored in an [`ItemSet`].
pub type DynItem<C> = dyn Item<CollectionType = C> + Send + Sync;

/// Implemented by [`items!`](crate::items) on the collection type (local type → no orphan impl).
#[doc(hidden)]
pub trait ItemList: Collection + Sized {
    fn frozen_set() -> Arc<ItemSet<Self>>;
}

impl<C: ItemList> Resolver<ItemSet<C>> for Container {
    fn resolve() -> Arc<ItemSet<C>> {
        C::frozen_set()
    }
}