pub struct Mutex<T, R = NoopRawMutex>where
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§
Source§impl<T, R> Mutex<T, R>where
R: RawMutex,
impl<T, R> Mutex<T, R>where
R: RawMutex,
Source§impl<T, R> Mutex<T, R>
impl<T, R> Mutex<T, R>
Sourcepub const fn const_new(raw_mutex: R, val: T) -> Mutex<T, R>
pub const fn const_new(raw_mutex: R, val: T) -> Mutex<T, R>
Creates a new mutex based on a pre-existing raw mutex.
This allows creating a mutex in a constant context on stable Rust.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes this mutex, returning the underlying data.
Trait Implementations§
Auto Trait Implementations§
impl<T, R = NoopRawMutex> !Freeze for Mutex<T, R>
impl<T, R = NoopRawMutex> !RefUnwindSafe for Mutex<T, R>
impl<T, R> Unpin for Mutex<T, R>
impl<T, R> UnsafeUnpin for Mutex<T, R>
impl<T, R> UnwindSafe for Mutex<T, R>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more