Slock
A mutex for Rust that never deadlocks.
A Slock, or Smart Lock, is a smart wrapper around an atomically reference counted read/write lock.
All accesses and modifications are done in a contained manner. This ensures that threads will never deadlock on a Slock operation.
// Create a new lock with an initial value
let lock = new;
// Change the lock's value
lock.set.await;
// Get the lock's value if Copy
let value = lock.get.await;
// Get the lock's value if Clone
let value = lock.get_clone.await;
assert_eq!;
It's also possible to extract only the data you need from larger structures without the need to clone the entire thing.
let user = new;
// Extract something that is Copy
let age = user.map.await;
// Extract something that is Clone
let name = user.map.await;
// Increment `age` by 1
user.set.await;