ulo 0.1.0-alpha.1

Fast and modular web framework for scalable applications
Documentation
use crate::dependency::{FromContainer, Requirement};
use crate::error::LookupError;
use crate::resolver::Resolver;
use crate::scope::{AllowedIn, Scope};

/// `None` exactly when `S` would fail with `LookupError::NotFound`: a key no module binds, an
/// extension no guard has written, an input this execution did not seed. Every other error
/// propagates: a construction failure, `ExecutionRequired`, an ambiguous key or module.
impl<S: FromContainer> FromContainer for Option<S> {
    fn describe(req: &mut Requirement) {
        req.optional::<S>();
    }

    async fn from_container(r: &Resolver<'_>) -> Result<Self, LookupError> {
        match S::from_container(r).await {
            Ok(value) => Ok(Some(value)),
            Err(LookupError::NotFound { .. }) => Ok(None),
            Err(other) => Err(other),
        }
    }
}

impl<X: AllowedIn<S>, S: Scope> AllowedIn<S> for Option<X> {}