use id_manager::PrimaryIdManager;
use ioc;
use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard};
#[doc(hidden)]
pub trait IdMgrMode<'a, IdMgr>
where IdMgr: PrimaryIdManager
{
type Ret: 'a;
fn retrieve(ids: &'a RwLock<IdMgr>) -> Self::Ret;
}
impl<'a, IdMgr> IdMgrMode<'a, IdMgr> for ()
where IdMgr: PrimaryIdManager
{
type Ret = ();
fn retrieve(_: &'a RwLock<IdMgr>) -> Self::Ret { () }
}
impl<'a, IdMgr> IdMgrMode<'a, IdMgr> for ioc::Read<IdMgr>
where IdMgr: PrimaryIdManager
{
type Ret = RwLockReadGuard<'a, IdMgr>;
fn retrieve(ids: &'a RwLock<IdMgr>) -> Self::Ret { ids.read().unwrap() }
}
impl<'a, IdMgr> IdMgrMode<'a, IdMgr> for ioc::Write<IdMgr>
where IdMgr: PrimaryIdManager
{
type Ret = RwLockWriteGuard<'a, IdMgr>;
fn retrieve(ids: &'a RwLock<IdMgr>) -> Self::Ret { ids.write().unwrap() }
}