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
let value = lock.get.await;
// Or if the value doesn't implement copy
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.
// A user struct that doesn't implement copy
let user = new;
// Get just the name
// This performs a clone on only the name
let name = user.map.await;
// Get just the age
// Extracts only the age, leaving everything else untouched
let age = user.map.await;