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§
Required Methods§
Sourcefn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>)
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.
Sourceunsafe fn guard(&self) -> Self::Guard<'_>
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.
Sourceunsafe fn data_mut(&self) -> Self::DataMut<'_>
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.