Struct slock::Slock

source ·
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§

Create a new Slock with a given initial value.

Extract inner values from within a Slock

let name = lock.map(|v| v.name).await;

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;
👎Deprecated: Use clone() instead

Create’s a new lock pointing to the same data. Modifying the data in the new lock will result in seeing the same change in the old lock.

let lock = Slock::new(0i32);
let the_same_lock = lock.split();

Subscribe to changes in the lock.

hook will be called any time Slock::set is called.

Returns a clone of the lock’s data.

Create a new lock with data clone from this one.

Asyncronously push to a vec. Note that due to the nature of async code, order cannot be guaranteed.

Converts from Slock<Slock<T>> to Slock<T>

Create a new Slock powered HashMap

Insert / modify a value in the map at a given key.

Get a value from the map at a given key.

If a lock’s data implements copy, this will return an owned copy of it.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.