pub struct Slock<T> { /* private fields */ }
Expand description
The Slock
object.
An atomically reference counted read/write lock with special safety features to avoid deadlocks.
When used correctly (no nesting lock access functions), deadlocks should be impossible.
Implementations§
source§impl<T> Slock<T>
impl<T> Slock<T>
sourcepub async fn map<F, U>(&self, mapper: F) -> Result<U, Elapsed>where
F: FnOnce(&T) -> U,
pub async fn map<F, U>(&self, mapper: F) -> Result<U, Elapsed>where
F: FnOnce(&T) -> U,
Extract inner values from within a Slock
let name = lock.map(|v| v.name).await;
sourcepub async fn set<F>(&self, setter: F)where
F: FnOnce(T) -> T,
pub async fn set<F>(&self, setter: F)where
F: FnOnce(T) -> T,
A setter for changing the internal data of the lock.
let lock = Slock::new(1i32);
lock.set(|v| v + 1).await;
lock.set(|_| 6).await;
source§impl<T: Clone> Slock<T>
impl<T: Clone> Slock<T>
sourcepub async fn clone_deep(&self) -> Self
pub async fn clone_deep(&self) -> Self
Create a new lock with data clone from this one.