pub struct Cura<T: Sync + Send + ?Sized> { /* private fields */ }Expand description
a sort of an Arc that will both readwrite lock , be easy to handle and is cloneable
use cura::Cura;
let s=Cura::new(1);
let a=s.clone();
Implementations§
Source§impl<T: Sync + Send + ?Sized> Cura<T>
Cura public interface
impl<T: Sync + Send + ?Sized> Cura<T>
Cura public interface
Sourcepub fn read(&self) -> ReadGuard<'_, T>
pub fn read(&self) -> ReadGuard<'_, T>
readlock a ‘Cura’,returning a guard that can be dereferenced for read-only operations
Sourcepub fn write(&self) -> Guard<'_, T>
pub fn write(&self) -> Guard<'_, T>
writelock a ‘Cura’ , returning a guard that can be dereferenced for write-operations.
Sourcepub fn alter(&self, f: fn(&mut T) -> Option<()>) -> Option<()>
pub fn alter(&self, f: fn(&mut T) -> Option<()>) -> Option<()>
transparently take a writelock, attempt to mutate the value and then release the lock
use cura::Cura;
let t=Cura::new(1);
let res=t.alter(|x|{ //this is a mutable ref, can be altered that way
if(*x==1){
*x=2;
Some(()) //signal alteration
}else{
None //signal not altered
}
});
match res {
None=>{/* no change made*/},
Some(_)=>{/*change made*/},
}
Trait Implementations§
Source§impl<T: Sync + Send + ?Sized> Clone for Cura<T>
deref to make use simpler, this should also transparently
read-lock
clone to make new references of the object
impl<T: Sync + Send + ?Sized> Clone for Cura<T>
deref to make use simpler, this should also transparently read-lock clone to make new references of the object
impl<T: Send + Sync + ?Sized> Send for Cura<T>
implement send and sync since thats all we want
impl<T: Send + Sync + ?Sized> Sync for Cura<T>
Auto Trait Implementations§
impl<T> Freeze for Cura<T>where
T: ?Sized,
impl<T> !RefUnwindSafe for Cura<T>
impl<T> Unpin for Cura<T>where
T: ?Sized,
impl<T> !UnwindSafe for Cura<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more