1mod derivations;
7#[cfg(test)]
8mod tests;
9
10use std::sync::{
12 RwLock,
13 RwLockReadGuard,
14 RwLockWriteGuard
15};
16
17
18#[derive(Debug)]
24pub struct Cage<Type: ?Sized> {
25 being: RwLock<Type>
26}
27
28impl<Type: Sized> Cage<Type> {
30 pub const fn new(value: Type) -> Cage<Type> {return Self {
31 being: RwLock::new(value)
32 }}
33 pub fn release(self) -> Type {return self.being.into_inner().unwrap()}
34}
35
36impl<Type: ?Sized> Cage<Type> {
38 #[inline]
39 pub fn read<'valid>(&'valid self) -> RwLockReadGuard<'valid, Type> {return self.being.read().unwrap()}
40 #[inline]
41 pub fn write<'valid>(&'valid self) -> RwLockWriteGuard<'valid, Type> {return self.being.write().unwrap()}
42}
43
44impl<Type: Copy> Cage<Type> {
46 #[inline]
47 pub fn get(&self) -> Type {*self.read()}
48}
49
50impl<Type: Clone> Cage<Type> {
52 #[inline]
53 pub fn cloned(&self) -> Type {self.read().clone()}
54}