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 parkinglot::RwLock; use readwrite_api::{RwApi, RwApiWrapper, RwApiWrapperOwned};
fn do_something(mut x: impl RwApi
asserteq!(dosomething(RwApiWrapperOwned(1)), 2); asserteq!(dosomething(RwApiWrapperOwned(3)), 3); asserteq!(dosomething(&mut RwApiWrapperOwned(1)), 2); asserteq!(dosomething(&mut RwApiWrapperOwned(3)), 3);
asserteq!(dosomething(RwLock::new(1)), 2); asserteq!(dosomething(RwLock::new(3)), 3); asserteq!(dosomething(&RwLock::new(1)), 2); asserteq!(dosomething(&RwLock::new(3)), 3); asserteq!(dosomething(&mut RwLock::new(1)), 2); asserteq!(dosomething(&mut RwLock::new(3)), 3);
fn dosomethingref<'a>(mut x: impl RwApi
asserteq!(dosomethingref(RwApiWrapper(&mut 1)), 2); asserteq!(dosomethingref(RwApiWrapper(&mut 3)), 3); asserteq!(dosomethingref(&mut RwApiWrapper(&mut 1)), 2); asserteq!(dosomethingref(&mut RwApiWrapper(&mut 3)), 3);
asserteq!(dosomethingref(RwLock::new(&mut 1)), 2); asserteq!(dosomethingref(RwLock::new(&mut 3)), 3); asserteq!(dosomethingref(&RwLock::new(&mut 1)), 2); asserteq!(dosomethingref(&RwLock::new(&mut 3)), 3); asserteq!(dosomethingref(&mut RwLock::new(&mut 1)), 2); asserteq!(dosomethingref(&mut RwLock::new(&mut 3)), 3); ```