RoLock
Read Only Lock.
This is a wrapper around Arc<RwLock<T>> that only implements RwLock::read() operations.
Usage
Create a normal Arc<RwLock<T>> in thread_1, send a RoLock to thread_2:
let rw = new; // Regular Arc<RwLock<T>>.
let ro = new; // Read Only Lock.
assert!; // This can read...
*rw.write.unwrap = 1; // and write.
spawn;
thread_1still has full read/write controlthread_2can onlyRoLock::read()
This type guarantees at compile time that you cannot write because the function doesn't even exist:
let rw = new;
let ro = new;
ro.write; // Compile error!
Since the inner field of RoLock (self.0) is private, you can't call RwLock::write directly either:
let rw = new;
let ro = new;
ro.0.write; // Compile error!