qecs-core 0.0.13

Soon to be highly flexible Entity-Component-System framework, core lib.
Documentation
/// We don't store our primary id manager in an `ioc::Ioc`, so we'll have to come up 
/// with something similar for it to be usable by `Process`...
///
/// Maybe I'll create a library for this specific design pattern at some point.

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() }
}