Skip to main content

deorbit_core/resolver/
resolved.rs

1use crate::{Error, FromDi, Services, TypeMeta};
2use std::sync::Arc;
3
4pub type ResolvedMany<T> = Vec<Arc<T>>;
5pub type Resolved<T> = Arc<T>;
6
7impl<T: ?Sized + Send + Sync + 'static> FromDi for Resolved<T> {
8    fn depends_on() -> &'static [TypeMeta] {
9        &[]
10    }
11
12    fn produce(services: &Services) -> Result<Self, Error> {
13        services.resolve::<T>().ok_or(Error::missing::<T>())
14    }
15}
16
17impl<T: ?Sized + Send + Sync + 'static> FromDi for ResolvedMany<T> {
18    fn depends_on() -> &'static [TypeMeta] {
19        &[]
20    }
21
22    fn produce(services: &Services) -> Result<Self, Error> {
23        services
24            .resolve_all::<T>()
25            .ok_or(Error::missing::<T>())
26            .map(|x| x.collect())
27    }
28}