tokenlock
Provides a Send
-able cell type whose contents can be accessed only via an inforgeable token.
Examples
let mut token = new;
let lock = new;
assert_eq!;
let mut guard = lock.write.unwrap;
assert_eq!;
*guard = 2;
The lifetime of the returned reference is limited by both of the TokenLock
and Token
.
drop; // compile error: cannot outlive `TokenLock`
drop; // compile error: cannot outlive `Token`
This also prevents from forming a reference to the contained value when there already is a mutable reference to it:
let write_guard = lock.write.unwrap;
let read_guard = lock.read.unwrap; // compile error
While allowing multiple immutable references:
let read_guard1 = lock.read.unwrap;
let read_guard2 = lock.read.unwrap;
License: MIT/Apache-2.0