[−][src]Struct sublock::sync::prooflock::MainLock
A variant of RwLock
with sublocks that can be opened at no cost by providing a proof
that the main lock is opened.
use sublock::sync::prooflock::*; use std::collections::HashMap; type State = HashMap<usize, SubCell<usize>>; let data : MainLock<State> = MainLock::new(HashMap::new()); { println!("* Attempt to read in the MainLock."); let (_, guard) = data.read().unwrap(); assert_eq!(guard.len(), 0); } { println!("* Attempt to write in the MainLock."); let (proof, mut guard) = data.write().unwrap(); guard.insert(0, SubCell::new(&proof, 42)); assert_eq!(guard.len(), 1); } { println!("* Attempt to read in a SubCell."); let (proof, guard) = data.read().unwrap(); assert_eq!(guard.len(), 1); let cell = guard.get(&0).unwrap(); assert_eq!(*cell.borrow(&proof), 42); } { println!("* Attempt to read and write in a SubCell."); let (proof, guard) = data.write().unwrap(); assert_eq!(guard.len(), 1); let cell = guard.get(&0).unwrap(); assert_eq!(*cell.borrow(&proof), 42); *cell.borrow_mut(&proof) = 99; assert_eq!(*cell.borrow(&proof), 99); } { println!("* Check that the SubCell changes are kept."); let (proof, guard) = data.read().unwrap(); assert_eq!(guard.len(), 1); let cell = guard.get(&0).unwrap(); assert_eq!(*cell.borrow(&proof), 99); }
Methods
impl<T> MainLock<T>
[src]
pub fn new(value: T) -> Self
[src]
pub fn read(&self) -> LockResult<ReadGuard<T>>
[src]
pub fn try_read(&self) -> TryLockResult<ReadGuard<T>>
[src]
pub fn write(&self) -> LockResult<WriteGuard<T>>
[src]
pub fn try_write(&self) -> TryLockResult<WriteGuard<T>>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
🔬 This is a nightly-only experimental API. (
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
🔬 This is a nightly-only experimental API. (
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,