pub use self::ext::{Dependencies, Resolve};
mod ext;
use std::any::{Any, TypeId};
use std::collections::HashMap;
use std::marker::PhantomData;
use std::sync::{Arc, Mutex};
use super::{Component, Construct, };
pub struct Graph<M>(Arc<Shared>, PhantomData<M>) where M: ?Sized;
type Dyn = Box<Any + 'static + Send>;
type Container = HashMap<TypeId, Dyn>;
type Shared = Mutex<Container>;
impl<M> Graph<M> where M: ?Sized {
pub fn new() -> Graph<M> {
let hash_map = HashMap::new();
let mutex = Mutex::new(hash_map);
let arc = Arc::new(mutex);
return Graph(arc, PhantomData);
}
pub fn dep<T>(&self) -> <Graph<M> as Resolve<T, M::Scope>>::CoImp
where M: Component<T>,
T: 'static + ?Sized,
Graph<M>: for<'imp> Resolve<'imp, T, M::Scope> {
self.__resolve()
}
pub fn construct<'dep, I>(&'dep self) -> I
where I: Construct<'dep>,
Graph<M>: Dependencies<'dep, <I as Construct<'dep>>::Dep> {
let deps = self.__dependencies();
I::__construct(deps)
}
}
impl<M> Clone for Graph<M> where M: ?Sized {
fn clone(&self) -> Self {
let &Graph(ref arc, ..) = self;
Graph(arc.clone(), PhantomData)
}
}