#![feature(test)]
#![feature(lock_value_accessors)]
extern crate test;
#[cfg(test)]
mod benches;
mod derivations;
#[cfg(test)]
mod tests;
use std::sync::{
RwLock,
RwLockReadGuard,
RwLockWriteGuard
};
#[derive(Debug)]
pub struct Cage<Type: ?Sized> {
being: RwLock<Type>
}
impl<Type: Sized> Cage<Type> {
#[inline]
pub const fn new(value: Type) -> Cage<Type> {return Self {
being: RwLock::new(value)
}}
#[inline]
pub fn release(self) -> Type {return self.being.into_inner().unwrap()}
#[inline]
pub fn replace(&self, value: Type) -> () {self.being.replace(value).unwrap();}
}
impl<Type: ?Sized> Cage<Type> {
#[inline]
pub fn read<'valid>(&'valid self) -> RwLockReadGuard<'valid, Type> {return self.being.read().unwrap()}
#[inline]
pub fn write<'valid>(&'valid self) -> RwLockWriteGuard<'valid, Type> {return self.being.write().unwrap()}
}
impl<Type: Copy> Cage<Type> {
#[inline]
pub fn get(&self) -> Type {*self.read()}
}
impl<Type: Clone> Cage<Type> {
#[inline]
pub fn cloned(&self) -> Type {self.read().clone()}
}