From 654a46976347e665588e65afe86bbea6a2b6098c Mon Sep 17 00:00:00 2001 From: Botahamec Date: Fri, 27 Sep 2024 20:01:25 -0400 Subject: Document LockableAsMut and LockableIntoInner --- src/lockable.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src') diff --git a/src/lockable.rs b/src/lockable.rs index 6eced32..e32fccd 100644 --- a/src/lockable.rs +++ b/src/lockable.rs @@ -151,15 +151,39 @@ pub unsafe trait Lockable { unsafe fn read_guard(&self) -> Self::ReadGuard<'_>; } +/// A trait which indicates that `into_inner` is a valid operation for a +/// [`Lockable`]. +/// +/// This is used for types like [`Poisonable`] to access the inner value of a +/// lock. [`Poisonable::into_inner`] calls [`LockableIntoInner::into_inner`] to +/// return a mutable reference of the inner value. This isn't implemented for +/// some `Lockable`s, such as `&[T]`. +/// +/// [`Poisonable`]: `crate::Poisonable` +/// [`Poisonable::into_inner`]: `crate::poisonable::Poisonable::into_inner` pub trait LockableIntoInner: Lockable { + /// The inner type that is behind the lock type Inner; + /// Consumes the lock, returning the underlying the lock. fn into_inner(self) -> Self::Inner; } +/// A trait which indicates that `as_mut` is a valid operation for a +/// [`Lockable`]. +/// +/// This is used for types like [`Poisonable`] to access the inner value of a +/// lock. [`Poisonable::get_mut`] calls [`LockableAsMut::as_mut`] to return a +/// mutable reference of the inner value. This isn't implemented for some +/// `Lockable`s, such as `&[T]`. +/// +/// [`Poisonable`]: `crate::Poisonable` +/// [`Poisonable::get_mut`]: `crate::poisonable::Poisonable::get_mut` pub trait LockableAsMut: Lockable { + /// The inner type that is behind the lock type Inner; + /// Returns a mutable reference to the underlying data. fn as_mut(&mut self) -> &mut Self::Inner; } -- cgit v1.2.3