Skip to main content

Lockable

Trait Lockable 

Source
pub unsafe trait Lockable {
    type Guard<'g>
       where Self: 'g;
    type DataMut<'a>
       where Self: 'a;

    // Required methods
    fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>);
    unsafe fn guard(&self) -> Self::Guard<'_>;
    unsafe fn data_mut(&self) -> Self::DataMut<'_>;
}
Expand description

A type that may be locked and unlocked.

This trait is usually implemented on collections of RawLocks. For example, a Vec<Mutex<i32>>.

§Safety

Acquiring the locks returned by get_ptrs must allow access to the values returned by guard.

Dropping the Guard must unlock those same locks.

The order of the resulting list from get_ptrs must be deterministic. As long as the value is not mutated, the references must always be in the same order.

The list returned by get_ptrs must contain any lock which could possibly be referenced in another collection.

Required Associated Types§

Source

type Guard<'g> where Self: 'g

The exclusive guard that does not hold a key

Source

type DataMut<'a> where Self: 'a

A reference to the protected data

Required Methods§

Source

fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>)

Yields a list of references to the RawLocks contained within this value.

These reference locks which must be locked before acquiring a guard, and unlocked when the guard is dropped. The order of the resulting list is deterministic. As long as the value is not mutated, the references will always be in the same order.

Source

unsafe fn guard(&self) -> Self::Guard<'_>

Returns a guard that can be used to access the underlying data mutably.

§Safety

All locks given by calling Lockable::get_ptrs must be locked exclusively before calling this function. The locks must not be unlocked until this guard is dropped.

Source

unsafe fn data_mut(&self) -> Self::DataMut<'_>

Returns a mutable reference to the data protected by this lock.

§Safety

All locks given by calling Lockable::get_ptrs must be locked exclusively before calling this function. The locks must not be unlocked until the lifetime of this reference ends.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<A: Lockable> Lockable for (A,)

Source§

type Guard<'g> = (<A as Lockable>::Guard<'g>,) where Self: 'g

Source§

type DataMut<'a> = (<A as Lockable>::DataMut<'a>,) where Self: 'a

Source§

fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>)

Source§

unsafe fn guard(&self) -> Self::Guard<'_>

Source§

unsafe fn data_mut(&self) -> Self::DataMut<'_>

Source§

impl<A: Lockable, B: Lockable> Lockable for (A, B)

Source§

type Guard<'g> = (<A as Lockable>::Guard<'g>, <B as Lockable>::Guard<'g>) where Self: 'g

Source§

type DataMut<'a> = (<A as Lockable>::DataMut<'a>, <B as Lockable>::DataMut<'a>) where Self: 'a

Source§

fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>)

Source§

unsafe fn guard(&self) -> Self::Guard<'_>

Source§

unsafe fn data_mut(&self) -> Self::DataMut<'_>

Source§

impl<A: Lockable, B: Lockable, C: Lockable> Lockable for (A, B, C)

Source§

type Guard<'g> = (<A as Lockable>::Guard<'g>, <B as Lockable>::Guard<'g>, <C as Lockable>::Guard<'g>) where Self: 'g

Source§

type DataMut<'a> = (<A as Lockable>::DataMut<'a>, <B as Lockable>::DataMut<'a>, <C as Lockable>::DataMut<'a>) where Self: 'a

Source§

fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>)

Source§

unsafe fn guard(&self) -> Self::Guard<'_>

Source§

unsafe fn data_mut(&self) -> Self::DataMut<'_>

Source§

impl<A: Lockable, B: Lockable, C: Lockable, D: Lockable> Lockable for (A, B, C, D)

Source§

type Guard<'g> = (<A as Lockable>::Guard<'g>, <B as Lockable>::Guard<'g>, <C as Lockable>::Guard<'g>, <D as Lockable>::Guard<'g>) where Self: 'g

Source§

type DataMut<'a> = (<A as Lockable>::DataMut<'a>, <B as Lockable>::DataMut<'a>, <C as Lockable>::DataMut<'a>, <D as Lockable>::DataMut<'a>) where Self: 'a

Source§

fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>)

Source§

unsafe fn guard(&self) -> Self::Guard<'_>

Source§

unsafe fn data_mut(&self) -> Self::DataMut<'_>

Source§

impl<A: Lockable, B: Lockable, C: Lockable, D: Lockable, E: Lockable> Lockable for (A, B, C, D, E)

Source§

type Guard<'g> = (<A as Lockable>::Guard<'g>, <B as Lockable>::Guard<'g>, <C as Lockable>::Guard<'g>, <D as Lockable>::Guard<'g>, <E as Lockable>::Guard<'g>) where Self: 'g

Source§

type DataMut<'a> = (<A as Lockable>::DataMut<'a>, <B as Lockable>::DataMut<'a>, <C as Lockable>::DataMut<'a>, <D as Lockable>::DataMut<'a>, <E as Lockable>::DataMut<'a>) where Self: 'a

Source§

fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>)

Source§

unsafe fn guard(&self) -> Self::Guard<'_>

Source§

unsafe fn data_mut(&self) -> Self::DataMut<'_>

Source§

impl<A: Lockable, B: Lockable, C: Lockable, D: Lockable, E: Lockable, F: Lockable> Lockable for (A, B, C, D, E, F)

Source§

type Guard<'g> = (<A as Lockable>::Guard<'g>, <B as Lockable>::Guard<'g>, <C as Lockable>::Guard<'g>, <D as Lockable>::Guard<'g>, <E as Lockable>::Guard<'g>, <F as Lockable>::Guard<'g>) where Self: 'g

Source§

type DataMut<'a> = (<A as Lockable>::DataMut<'a>, <B as Lockable>::DataMut<'a>, <C as Lockable>::DataMut<'a>, <D as Lockable>::DataMut<'a>, <E as Lockable>::DataMut<'a>, <F as Lockable>::DataMut<'a>) where Self: 'a

Source§

fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>)

Source§

unsafe fn guard(&self) -> Self::Guard<'_>

Source§

unsafe fn data_mut(&self) -> Self::DataMut<'_>

Source§

impl<A: Lockable, B: Lockable, C: Lockable, D: Lockable, E: Lockable, F: Lockable, G: Lockable> Lockable for (A, B, C, D, E, F, G)

Source§

type Guard<'g> = (<A as Lockable>::Guard<'g>, <B as Lockable>::Guard<'g>, <C as Lockable>::Guard<'g>, <D as Lockable>::Guard<'g>, <E as Lockable>::Guard<'g>, <F as Lockable>::Guard<'g>, <G as Lockable>::Guard<'g>) where Self: 'g

Source§

type DataMut<'a> = (<A as Lockable>::DataMut<'a>, <B as Lockable>::DataMut<'a>, <C as Lockable>::DataMut<'a>, <D as Lockable>::DataMut<'a>, <E as Lockable>::DataMut<'a>, <F as Lockable>::DataMut<'a>, <G as Lockable>::DataMut<'a>) where Self: 'a

Source§

fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>)

Source§

unsafe fn guard(&self) -> Self::Guard<'_>

Source§

unsafe fn data_mut(&self) -> Self::DataMut<'_>

Source§

impl<T: Lockable> Lockable for &T

Source§

type Guard<'g> = <T as Lockable>::Guard<'g> where Self: 'g

Source§

type DataMut<'a> = <T as Lockable>::DataMut<'a> where Self: 'a

Source§

fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>)

Source§

unsafe fn guard(&self) -> Self::Guard<'_>

Source§

unsafe fn data_mut(&self) -> Self::DataMut<'_>

Source§

impl<T: Lockable> Lockable for &mut T

Source§

type Guard<'g> = <T as Lockable>::Guard<'g> where Self: 'g

Source§

type DataMut<'a> = <T as Lockable>::DataMut<'a> where Self: 'a

Source§

fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>)

Source§

unsafe fn guard(&self) -> Self::Guard<'_>

Source§

unsafe fn data_mut(&self) -> Self::DataMut<'_>

Source§

impl<T: Lockable> Lockable for Box<[T]>

Source§

type Guard<'g> = Box<[<T as Lockable>::Guard<'g>]> where Self: 'g

Source§

type DataMut<'a> = Box<[<T as Lockable>::DataMut<'a>]> where Self: 'a

Source§

fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>)

Source§

unsafe fn guard(&self) -> Self::Guard<'_>

Source§

unsafe fn data_mut(&self) -> Self::DataMut<'_>

Source§

impl<T: Lockable> Lockable for Vec<T>

Source§

type Guard<'g> = Box<[<T as Lockable>::Guard<'g>]> where Self: 'g

Source§

type DataMut<'a> = Box<[<T as Lockable>::DataMut<'a>]> where Self: 'a

Source§

fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>)

Source§

unsafe fn guard(&self) -> Self::Guard<'_>

Source§

unsafe fn data_mut(&self) -> Self::DataMut<'_>

Source§

impl<T: Lockable, const N: usize> Lockable for [T; N]

Source§

type Guard<'g> = [<T as Lockable>::Guard<'g>; N] where Self: 'g

Source§

type DataMut<'a> = [<T as Lockable>::DataMut<'a>; N] where Self: 'a

Source§

fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>)

Source§

unsafe fn guard<'g>(&'g self) -> Self::Guard<'g>

Source§

unsafe fn data_mut<'a>(&'a self) -> Self::DataMut<'a>

Implementors§

Source§

impl<L: Lockable> Lockable for BoxedLockCollection<L>

Source§

type Guard<'g> = <L as Lockable>::Guard<'g> where Self: 'g

Source§

type DataMut<'a> = <L as Lockable>::DataMut<'a> where Self: 'a

Source§

impl<L: Lockable> Lockable for OwnedLockCollection<L>

Source§

type Guard<'g> = <L as Lockable>::Guard<'g> where Self: 'g

Source§

type DataMut<'a> = <L as Lockable>::DataMut<'a> where Self: 'a

Source§

impl<L: Lockable> Lockable for RefLockCollection<'_, L>

Source§

type Guard<'g> = <L as Lockable>::Guard<'g> where Self: 'g

Source§

type DataMut<'a> = <L as Lockable>::DataMut<'a> where Self: 'a

Source§

impl<L: Lockable> Lockable for RetryingLockCollection<L>

Source§

type Guard<'g> = <L as Lockable>::Guard<'g> where Self: 'g

Source§

type DataMut<'a> = <L as Lockable>::DataMut<'a> where Self: 'a

Source§

impl<L: Lockable> Lockable for Poisonable<L>

Source§

type Guard<'g> = Result<PoisonRef<'g, <L as Lockable>::Guard<'g>>, PoisonError<PoisonRef<'g, <L as Lockable>::Guard<'g>>>> where Self: 'g

Source§

type DataMut<'a> = Result<<L as Lockable>::DataMut<'a>, PoisonError<<L as Lockable>::DataMut<'a>>> where Self: 'a

Source§

impl<T, R: RawMutex> Lockable for Mutex<T, R>

Source§

type Guard<'g> = MutexRef<'g, T, R> where Self: 'g

Source§

type DataMut<'a> = &'a mut T where Self: 'a

Source§

impl<T, R: RawRwLock> Lockable for RwLock<T, R>

Source§

type Guard<'g> = RwLockWriteRef<'g, T, R> where Self: 'g

Source§

type DataMut<'a> = &'a mut T where Self: 'a