Provides an interface to unify single-threaded code and RwLocks-based code.
A nice side effect of this trait is manifested in the activation
of the borrow-checker to check the absence of deadlocks introduced in the current scope.
This is because Self::write
can now only be called on a mutable,
but not constant, reference.
```rust use readwriteapi::{ReadWriteApi, TrivialReadWriteApi}; use parking_lot::RwLock;
struct A(u64);
fn do_something(mut x: impl ReadWriteApi
impl TrivialReadWriteApi for A {}
asserteq!(dosomething(A(1)), 2); asserteq!(dosomething(A(3)), 3); asserteq!(dosomething(&RwLock::new(A(1))), 2); asserteq!(dosomething(&RwLock::new(A(3))), 3); asserteq!(dosomething(RwLock::new(A(1))), 2); asserteq!(dosomething(RwLock::new(A(3))), 3);
fn dosomethingref<'a>(mut x: impl ReadWriteApi
impl TrivialReadWriteApi for &mut A {}
asserteq!(dosomethingref(&mut A(1)), 2); asserteq!(dosomethingref(&mut A(3)), 3); asserteq!(dosomethingref(&RwLock::new(&mut A(1))), 2); asserteq!(dosomethingref(&RwLock::new(&mut A(3))), 3); asserteq!(dosomethingref(RwLock::new(&mut A(1))), 2); asserteq!(dosomethingref(RwLock::new(&mut A(3))), 3) ```