LockedAt

Struct LockedAt 

Source
pub struct LockedAt<'a, L>(/* private fields */);
Expand description

Empty type that enforces lock acquisition ordering.

This type wraps a lock level L representing the level of the “currently held” lock, and provides methods for accessing state for other lock levels. For a given L, the methods on LockedAt<'_, L> will allow accessing state for a lock level M if M: LockAfter<L>.

The with_ methods on this type will (if they don’t return an error), produce two values: a new LockedAt instance and an accessor for locked state. Both values will exclusively borrow the original LockedAt instance, preventing its use, until the new values go out of scope.

Implementations§

Source§

impl LockedAt<'static, Unlocked>

Source

pub fn new() -> Self

Creates a new LockedAt without any locks held.

Source§

impl<L> LockedAt<'_, L>

Source

pub fn with_lock<'a, NewLock>( &'a mut self, t: &'a NewLock::Mutex, ) -> Result<(LockedAt<'a, NewLock>, <NewLock::Mutex as MutexLock>::Guard<'a>), <NewLock::Mutex as MutexLock>::Error<'a>>
where NewLock: MutexLockLevel, L: LockBefore<NewLock>,

Attempts to acquire a lock on NewLock state.

Assuming NewLock is a lock level that can be acquired after L, this method provides access to state held in the MutexLock type NewLock::Mutex. If the lock acquisition fails, an error will be returned. Otherwise, this method returns a new LockedAt along with an accessor for the held state.

If no further LockedAt calls need to be made after this one, consider using LockedAt::lock instead.

Source

pub fn with_read_lock<'a, NewLock>( &'a mut self, t: &'a NewLock::RwLock, ) -> Result<(LockedAt<'a, NewLock>, <NewLock::RwLock as RwLock>::ReadGuard<'a>), <NewLock::RwLock as RwLock>::ReadError<'a>>
where NewLock: RwLockLevel, L: LockBefore<NewLock>,

Attempts to acquire a shared lock on NewLock state.

Assuming NewLock is a lock level that can be acquired after L, this method provides access to state held in the ReadWrite type NewLock::RwLock. If the lock acquisition fails, an error will be returned. Otherwise, this method returns a new LockedAt along with a read-only accessor for the held state.

If no further LockedAt calls need to be made after this one, consider using LockedAt::read_lock instead.

Source

pub fn with_write_lock<'a, NewLock>( &'a mut self, t: &'a NewLock::RwLock, ) -> Result<(LockedAt<'a, NewLock>, <NewLock::RwLock as RwLock>::WriteGuard<'a>), <NewLock::RwLock as RwLock>::WriteError<'a>>
where NewLock: RwLockLevel, L: LockBefore<NewLock>,

Attempts to acquire an exclusive lock on NewLock state.

Assuming NewLock is a lock level that can be acquired after L, this method provides access to state held in the ReadWrite type T. If the lock acquisition fails, an error will be returned. Otherwise, this method returns a new LockedAt along with a read/write accessor for the held state.

If no further LockedAt calls need to be made after this one, consider using LockedAt::write_lock instead.

Source§

impl<L> LockedAt<'_, L>

Source

pub fn lock<'a, NewLock>( &'a mut self, t: &'a NewLock::Mutex, ) -> Result<<NewLock::Mutex as MutexLock>::Guard<'a>, <NewLock::Mutex as MutexLock>::Error<'a>>
where NewLock: 'a + MutexLockLevel, L: LockBefore<NewLock>,

Provides access to a MutexLock’s state.

Source

pub fn read_lock<'a, NewLock>( &'a mut self, t: &'a NewLock::RwLock, ) -> Result<<NewLock::RwLock as RwLock>::ReadGuard<'a>, <NewLock::RwLock as RwLock>::ReadError<'a>>
where NewLock: RwLockLevel + 'a, L: LockBefore<NewLock>,

Provides read access to a RwLock’s state.

Source

pub fn write_lock<'a, NewLock>( &'a mut self, t: &'a NewLock::RwLock, ) -> Result<<NewLock::RwLock as RwLock>::WriteGuard<'a>, <NewLock::RwLock as RwLock>::WriteError<'a>>
where NewLock: RwLockLevel + 'a, L: LockBefore<NewLock>,

Provides read/write access to a RwLock’s state.

Source§

impl<L> LockedAt<'_, L>

Source

pub async fn wait_for_lock<'a, NewLock>( &'a mut self, t: &'a NewLock::Mutex, ) -> (LockedAt<'a, NewLock>, <NewLock::Mutex as AsyncMutexLock>::Guard<'a>)
where NewLock: AsyncMutexLockLevel + 'a, L: LockBefore<NewLock>,

Asynchronously acquires a lock on NewLock state.

Assuming NewLock is a lock level that can be acquired after L, this method provides access to state held in the AsyncMutexLock type NewLock::Mutex, yielding the current task until the lock can be acquired. Once the state is locked, returns a guard for accessing it and a new LockedAt instance that can be used to acquire additional locks.

If no further LockedAt calls need to be made after this one, consider using LockedAt::wait_lock instead.

Source

pub async fn wait_for_read<'a, NewLock>( &'a mut self, t: &'a NewLock::RwLock, ) -> (LockedAt<'a, NewLock>, <NewLock::RwLock as AsyncRwLock>::ReadGuard<'a>)
where NewLock: AsyncRwLockLevel + 'a, L: LockBefore<NewLock>,

Asynchronously acquires a shared lock on NewLock state.

Assuming NewLock is a lock level that can be acquired after L, this method provides access to state held in the ReadWrite type T. This method will yield the current task until the lock can be acquired. Once the state is locked, this method returns a guard for accessing it and a new LockedAt instance that can be used to acquire additional locks.

If no further LockedAt calls need to be made after this one, consider using LockedAt::wait_read instead.

Source

pub async fn wait_for_write<'a, NewLock>( &'a mut self, t: &'a NewLock::RwLock, ) -> (LockedAt<'a, NewLock>, <NewLock::RwLock as AsyncRwLock>::WriteGuard<'a>)
where NewLock: AsyncRwLockLevel + 'a, L: LockBefore<NewLock>,

Attempts to acquire an exclusive lock on NewLock state.

Assuming NewLock is a lock level that can be acquired after L, this method provides access to state held in the ReadWrite type T. If the lock acquisition fails, an error will be returned. Otherwise, this method returns a new LockedAt along with a read/write accessor for the held state.

If no further LockedAt calls need to be made after this one, consider using LockedAt::write_lock instead.

Source§

impl<L> LockedAt<'_, L>

Source

pub async fn wait_lock<'a, NewLock>( &'a mut self, t: &'a NewLock::Mutex, ) -> <NewLock::Mutex as AsyncMutexLock>::Guard<'a>
where NewLock: 'a + AsyncMutexLockLevel, L: LockBefore<NewLock>,

Asynchronously provides access to an AsyncMutexLock’s state.

Source

pub async fn wait_read<'a, NewLock>( &'a mut self, t: &'a NewLock::RwLock, ) -> <NewLock::RwLock as AsyncRwLock>::ReadGuard<'a>
where NewLock: AsyncRwLockLevel + 'a, L: LockBefore<NewLock>,

Asynchronously provides read access to an AsyncRwLock’s state.

Source

pub async fn wait_write<'a, NewLock>( &'a mut self, t: &'a NewLock::RwLock, ) -> <NewLock::RwLock as AsyncRwLock>::WriteGuard<'a>
where NewLock: AsyncRwLockLevel + 'a, L: LockBefore<NewLock>,

Asynchronously provides read/write access to an AsyncRwLock’s state.

Auto Trait Implementations§

§

impl<'a, L> Freeze for LockedAt<'a, L>

§

impl<'a, L> RefUnwindSafe for LockedAt<'a, L>
where L: RefUnwindSafe,

§

impl<'a, L> Send for LockedAt<'a, L>
where L: Send,

§

impl<'a, L> Sync for LockedAt<'a, L>
where L: Sync,

§

impl<'a, L> Unpin for LockedAt<'a, L>

§

impl<'a, L> !UnwindSafe for LockedAt<'a, L>

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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<Before, After> LockBefore<After> for Before
where After: LockAfter<Before>,