Struct ruspiro_lock::sync::Mutex[][src]

#[repr(C, align(16))]
pub struct Mutex<T: ?Sized> { /* fields omitted */ }
Expand description

An mutual exclusive access lock for the interior data

Implementations

Create a new data access guarding lock

Try to lock the interior data for mutual exclusive access. Returns None if the lock failes or Some(MutexGuard). The actual data, the MutexGuard wraps could be conviniently accessed by dereferencing it.

Example
static DATA: Mutex<u32> = Mutex::new(10);
    if let Some(data) = DATA.try_lock() {
        // do something with data
    }

Lock the guarded data for mutual exclusive access. This blocks until the data could be successfully locked. The locked data will be returned as MutexGuard. Simply dereferencing this allows access to the contained data value.

Example
static DATA: Mutex<u32> = Mutex::new(10);
    let mut data = DATA.lock();
    // do something with data
    *data = 15;

Consume the Mutex and return the inner value

Trait Implementations

Formats the value using the given formatter. Read more

The Mutex is always Sync, to make it Send as well it need to be wrapped into an Arc.

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

Performs the conversion.

Performs the conversion.

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.