use service::ServiceBase;
use store::StoreBase;
use id_manager::PrimaryIdManager;
use buffer::BufferBase;
use idmgr_mode;
use ioc::{Ioc, InvocationMethod};
use std::fmt::Debug;
use std::sync::RwLock;
pub trait ProcessBase<IdMgr, Key, StoBase: ?Sized, BufBase: ?Sized, SerBase: ?Sized>: ServiceBase
where
IdMgr: PrimaryIdManager,
Key: Debug + Ord,
StoBase: StoreBase<Id = IdMgr::Id>,
BufBase: BufferBase,
SerBase: ServiceBase,
{
fn _update(
&mut self,
ids: &RwLock<IdMgr>,
stores: &Ioc<Key, StoBase>,
buffer: &Ioc<Key, BufBase>,
services: &Ioc<Key, SerBase>,
);
}
pub trait Process<'a, IdMgr, Key, StoBase: ?Sized, BufBase: ?Sized, SerBase: ?Sized, >: ServiceBase
where
IdMgr: PrimaryIdManager,
Key: Debug + Ord,
StoBase: StoreBase<Id = IdMgr::Id>,
BufBase: BufferBase,
SerBase: ServiceBase,
{
type IdMgrMode: idmgr_mode::IdMgrMode<'a, IdMgr>;
type StoreSelection: InvocationMethod<'a, Key, StoBase>;
type BufferSelection: InvocationMethod<'a, Key, BufBase>;
type ServiceSelection: InvocationMethod<'a, Key, SerBase>;
type IdMgr = <Self::IdMgrMode as idmgr_mode::IdMgrMode<'a, IdMgr>>::Ret;
type Stores = <Self::StoreSelection as InvocationMethod<'a, Key, StoBase>>::Ret;
type Buffers = <Self::BufferSelection as InvocationMethod<'a, Key, BufBase>>::Ret;
type Services = <Self::ServiceSelection as InvocationMethod<'a, Key, SerBase>>::Ret;
fn update(
&mut self,
ids: <Self::IdMgrMode as idmgr_mode::IdMgrMode<'a, IdMgr>>::Ret,
stores: <Self::StoreSelection as InvocationMethod<'a, Key, StoBase>>::Ret,
buffer: <Self::BufferSelection as InvocationMethod<'a, Key, BufBase>>::Ret,
services: <Self::ServiceSelection as InvocationMethod<'a, Key, SerBase>>::Ret,
);
}
impl<T, IdMgr, Key, StoBase: ?Sized, BufBase: ?Sized, SerBase: ?Sized> ProcessBase<IdMgr, Key, StoBase, BufBase, SerBase> for T
where
IdMgr: PrimaryIdManager,
Key: Debug + Ord,
StoBase: StoreBase<Id = IdMgr::Id>,
BufBase: BufferBase,
SerBase: ServiceBase,
T: for<'a> Process<'a, IdMgr, Key, StoBase, BufBase, SerBase>,
for<'a> <<T as Process<'a, IdMgr, Key, StoBase, BufBase, SerBase>>::StoreSelection as InvocationMethod<'a, Key, StoBase>>::Args: Default,
for<'a> <<T as Process<'a, IdMgr, Key, StoBase, BufBase, SerBase>>::BufferSelection as InvocationMethod<'a, Key, BufBase>>::Args: Default,
for<'a> <<T as Process<'a, IdMgr, Key, StoBase, BufBase, SerBase>>::ServiceSelection as InvocationMethod<'a, Key, SerBase>>::Args: Default,
{
fn _update(
&mut self,
ids: &RwLock<IdMgr>,
stores: &Ioc<Key, StoBase>,
buffers: &Ioc<Key, BufBase>,
services: &Ioc<Key, SerBase>,
){
use std::mem;
assert_eq!(0, mem::size_of::<<T::StoreSelection as InvocationMethod<_, _>>::Args>());
assert_eq!(0, mem::size_of::<<T::BufferSelection as InvocationMethod<_, _>>::Args>());
assert_eq!(0, mem::size_of::<<T::ServiceSelection as InvocationMethod<_, _>>::Args>());
self.update(
<T::IdMgrMode as idmgr_mode::IdMgrMode<IdMgr>>::retrieve(ids),
stores.invoke::<T::StoreSelection>(Default::default()).unwrap(),
buffers.invoke::<T::BufferSelection>(Default::default()).unwrap(),
services.invoke::<T::ServiceSelection>(Default::default()).unwrap(),
);
}
}