pub struct IfMutex<T, M = NoopRawMutex>{ /* private fields */ }Expand description
Async mutex with conditional locking based on the data inside the mutex.
Check embassy_sync::Mutex for the original unconditional implementation.
Implementations§
Source§impl<T, M> IfMutex<T, M>
impl<T, M> IfMutex<T, M>
Sourcepub async fn lock(&self) -> IfMutexGuard<'_, T, M>
pub async fn lock(&self) -> IfMutexGuard<'_, T, M>
Lock the mutex.
This will wait for the mutex to be unlocked if it’s already locked.
Sourcepub async fn lock_if<F>(&self, f: F) -> IfMutexGuard<'_, T, M>
pub async fn lock_if<F>(&self, f: F) -> IfMutexGuard<'_, T, M>
Lock the mutex.
This will wait for the mutex to be unlocked if it’s already locked and for the provided condition on the data to become true.
Sourcepub async fn with<F, R>(&self, f: F) -> R
pub async fn with<F, R>(&self, f: F) -> R
Waits for the mutex to become unlocked and then executes the provided closure.
Will become ready only when the callback closure returns a Some result.
Sourcepub fn try_lock(&self) -> Result<IfMutexGuard<'_, T, M>, TryLockError>
pub fn try_lock(&self) -> Result<IfMutexGuard<'_, T, M>, TryLockError>
Attempt to immediately lock the mutex.
Sourcepub fn try_lock_if<F>(
&self,
f: F,
) -> Result<IfMutexGuard<'_, T, M>, TryLockError>
pub fn try_lock_if<F>( &self, f: F, ) -> Result<IfMutexGuard<'_, T, M>, TryLockError>
Attempt to immediately lock the mutex.
If the mutex is already locked or the condition on the data is not true, this will return an error instead of waiting.
Sourcepub fn into_inner(self) -> Twhere
T: Sized,
pub fn into_inner(self) -> Twhere
T: Sized,
Consumes this mutex, returning the underlying data.
Trait Implementations§
Auto Trait Implementations§
impl<T, M = NoopRawMutex> !Freeze for IfMutex<T, M>
impl<T, M = NoopRawMutex> !RefUnwindSafe for IfMutex<T, M>
impl<T, M> Unpin for IfMutex<T, M>
impl<T, M> UnsafeUnpin for IfMutex<T, M>
impl<T, M> UnwindSafe for IfMutex<T, M>
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