Skip to main content

IfMutex

Struct IfMutex 

Source
pub struct IfMutex<T, M = NoopRawMutex>
where M: RawMutex, T: ?Sized,
{ /* 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>
where M: RawMutex,

Async mutex.

Source

pub const fn new(value: T) -> IfMutex<T, M>

Create a new mutex with the given value.

Source

pub fn init<I>(value: I) -> impl Init<IfMutex<T, M>>
where I: Init<T>,

Creates a mutex in-place initializer with the given value initializer.

Source§

impl<T, M> IfMutex<T, M>
where M: RawMutex, T: ?Sized,

Source

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.

Source

pub async fn lock_if<F>(&self, f: F) -> IfMutexGuard<'_, T, M>
where F: Fn(&T) -> bool,

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.

Source

pub async fn with<F, R>(&self, f: F) -> R
where F: FnMut(&mut T) -> Option<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.

Source

pub fn try_lock(&self) -> Result<IfMutexGuard<'_, T, M>, TryLockError>

Attempt to immediately lock the mutex.

Source

pub fn try_lock_if<F>( &self, f: F, ) -> Result<IfMutexGuard<'_, T, M>, TryLockError>
where F: FnMut(&T) -> bool,

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.

Source

pub fn into_inner(self) -> T
where T: Sized,

Consumes this mutex, returning the underlying data.

Source

pub fn get_mut(&mut self) -> &mut T

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.

Trait Implementations§

Source§

impl<T, M> Send for IfMutex<T, M>
where T: Send + ?Sized, M: RawMutex + Send,

Source§

impl<T, M> Sync for IfMutex<T, M>
where T: Send + ?Sized, M: RawMutex + Sync,

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>
where T: Unpin + ?Sized, M: Unpin,

§

impl<T, M> UnsafeUnpin for IfMutex<T, M>
where T: UnsafeUnpin + ?Sized, M: UnsafeUnpin,

§

impl<T, M> UnwindSafe for IfMutex<T, M>
where T: UnwindSafe + ?Sized, M: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, E> Init<T, E> for T

Source§

unsafe fn __init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
Source§

fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, I> IntoFallibleInit<T> for I
where I: Init<T>,

Source§

fn into_fallible<E>(self) -> impl Init<T, E>

Convert the infallible initializer to a fallible one.
Source§

impl<Source, Target> OctetsInto<Target> for Source
where Target: OctetsFrom<Source>,

Source§

type Error = <Target as OctetsFrom<Source>>::Error

Source§

fn try_octets_into( self, ) -> Result<Target, <Source as OctetsInto<Target>>::Error>

Performs the conversion.
Source§

fn octets_into(self) -> Target
where Self::Error: Into<Infallible>,

Performs an infallible conversion.
Source§

impl<T, E> PinInit<T, E> for T

Source§

unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
Source§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>
where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V