pub struct Mutex<R, T: ?Sized> { /* private fields */ }
Expand description

Blocking mutex (not async)

Provides a blocking mutual exclusion primitive backed by an implementation of raw::RawMutex.

Which implementation you select depends on the context in which you’re using the mutex, and you can choose which kind of interior mutability fits your use case.

Use CriticalSectionMutex when data can be shared between threads and interrupts.

Use NoopMutex when data is only shared between tasks running on the same executor.

Use [ThreadModeMutex] when data is shared between tasks running on the same executor but you want a global singleton.

In all cases, the blocking mutex is intended to be short lived and not held across await points. Use the async Mutex if you need a lock that is held across await points.

Implementations

Creates a new mutex in an unlocked state ready for use.

Creates a critical section and grants temporary access to the protected data.

Creates a new mutex based on a pre-existing raw mutex.

This allows creating a mutex in a constant context on stable Rust.

Consumes this mutex, returning the underlying data.

Returns a mutable reference to the underlying data.

Since this call borrows the Mutex mutably, no actual locking needs to take place—the mutable borrow statically guarantees no locks exist.

Borrows the data for the duration of the critical section

Borrows the data

Trait Implementations

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 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.