1#![feature(test)]
7
8extern crate test;
10
11#[cfg(test)]
13mod benches;
14mod derivations;
15#[cfg(test)]
16mod tests;
17
18use std::sync::{
20 RwLock,
21 RwLockReadGuard,
22 RwLockWriteGuard
23};
24
25
26#[derive(Debug)]
32pub struct Cage<Type: ?Sized> {
33 being: RwLock<Type>
34}
35
36impl<Type: Sized> Cage<Type> {
38 pub const fn new(value: Type) -> Cage<Type> {return Self {
39 being: RwLock::new(value)
40 }}
41 pub fn release(self) -> Type {return self.being.into_inner().unwrap()}
42}
43
44impl<Type: ?Sized> Cage<Type> {
46 #[inline]
47 pub fn read<'valid>(&'valid self) -> RwLockReadGuard<'valid, Type> {return self.being.read().unwrap()}
48 #[inline]
49 pub fn write<'valid>(&'valid self) -> RwLockWriteGuard<'valid, Type> {return self.being.write().unwrap()}
50}
51
52impl<Type: Copy> Cage<Type> {
54 #[inline]
55 pub fn get(&self) -> Type {*self.read()}
56}
57
58impl<Type: Clone> Cage<Type> {
60 #[inline]
61 pub fn cloned(&self) -> Type {self.read().clone()}
62}