use crate::dependency::{FromContainer, Requirement};
use crate::error::LookupError;
use crate::resolver::Resolver;
use crate::scope::{AllowedIn, Scope};
impl<S: FromContainer> FromContainer for Option<S> {
fn describe(req: &mut Requirement) {
req.optional::<S>();
}
fn from_container(r: &Resolver<'_>) -> impl std::future::Future<Output = Result<Self, LookupError>> + Send {
let read = S::from_container(r);
async move {
match read.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> {}