noema 0.4.0

Noema IOC and DI framework for Rust
Documentation
use std::marker::PhantomData;
use std::sync::Arc;

use crate::core::Container;
use crate::di::KeyedResolver;

/// Handle for keyed lookups: key type `K` → service type `S`.
pub struct Keyed<K, S: ?Sized> {
    _marker: PhantomData<(K, S)>,
}

impl<K, S: ?Sized + Send + Sync + 'static> Keyed<K, S> {
    pub(crate) fn new() -> Self {
        Self {
            _marker: PhantomData,
        }
    }

    /// Look up a registered implementation by key (`K` must match the type used in the macro).
    pub fn one(&self, key: K) -> Option<Arc<S>>
    where
        K: PartialEq,
        Container: KeyedResolver<K, S>,
    {
        Container::resolve_keyed(key)
    }
}