A useful pattern I keep seeing around the internet for unwrapping Mutex
and RwLock
locks is to alias the unwrap for LockResult
:
use LockResult;
let num: = new;
*num.write .acquire = 20;
println!;
Because LockResult
will only ever be an Err
variant when there is a panic while an exclusive lock is in scope (for RwLocks), or when a lock is in scope (for Mutexes), we can unwrap the result so that any panic is propagated.
Additionally, PoisonError
has an into_inner()
function which allows you to recover the guard and have access to the data: