From 311842d28d1fbb6da945f0d98f1655f77a58abf9 Mon Sep 17 00:00:00 2001 From: Mica White Date: Wed, 25 Dec 2024 17:58:38 -0500 Subject: as_mut re-organization --- src/lockable.rs | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'src/lockable.rs') diff --git a/src/lockable.rs b/src/lockable.rs index 5cc7135..1154d16 100644 --- a/src/lockable.rs +++ b/src/lockable.rs @@ -160,14 +160,14 @@ pub trait LockableIntoInner: Lockable { /// /// [`Poisonable`]: `crate::Poisonable` /// [`Poisonable::get_mut`]: `crate::poisonable::Poisonable::get_mut` -pub trait LockableAsMut: Lockable { +pub trait LockableGetMut: Lockable { /// The inner type that is behind the lock type Inner<'a> where Self: 'a; /// Returns a mutable reference to the underlying data. - fn as_mut(&mut self) -> Self::Inner<'_>; + fn get_mut(&mut self) -> Self::Inner<'_>; } /// Allows a lock to be accessed by multiple readers. @@ -239,14 +239,14 @@ unsafe impl Lockable for &mut T { } } -impl LockableAsMut for &mut T { +impl LockableGetMut for &mut T { type Inner<'a> = T::Inner<'a> where Self: 'a; - fn as_mut(&mut self) -> Self::Inner<'_> { - (*self).as_mut() + fn get_mut(&mut self) -> Self::Inner<'_> { + (*self).get_mut() } } @@ -283,11 +283,11 @@ macro_rules! tuple_impls { } } - impl<$($generic: LockableAsMut,)*> LockableAsMut for ($($generic,)*) { + impl<$($generic: LockableGetMut,)*> LockableGetMut for ($($generic,)*) { type Inner<'a> = ($($generic::Inner<'a>,)*) where Self: 'a; - fn as_mut(&mut self) -> Self::Inner<'_> { - ($(self.$value.as_mut(),)*) + fn get_mut(&mut self) -> Self::Inner<'_> { + ($(self.$value.get_mut(),)*) } } @@ -343,17 +343,17 @@ unsafe impl Lockable for [T; N] { } } -impl LockableAsMut for [T; N] { +impl LockableGetMut for [T; N] { type Inner<'a> = [T::Inner<'a>; N] where Self: 'a; - fn as_mut(&mut self) -> Self::Inner<'_> { + fn get_mut(&mut self) -> Self::Inner<'_> { unsafe { let mut guards = MaybeUninit::<[MaybeUninit>; N]>::uninit().assume_init(); for (i, lock) in self.iter_mut().enumerate() { - guards[i].write(lock.as_mut()); + guards[i].write(lock.get_mut()); } guards.map(|g| g.assume_init()) @@ -411,14 +411,14 @@ unsafe impl Lockable for Box<[T]> { } } -impl LockableAsMut for Box<[T]> { +impl LockableGetMut for Box<[T]> { type Inner<'a> = Box<[T::Inner<'a>]> where Self: 'a; - fn as_mut(&mut self) -> Self::Inner<'_> { - self.iter_mut().map(LockableAsMut::as_mut).collect() + fn get_mut(&mut self) -> Self::Inner<'_> { + self.iter_mut().map(LockableGetMut::get_mut).collect() } } @@ -469,14 +469,14 @@ unsafe impl Lockable for Vec { // TODO: using edition 2024, impl LockableIntoInner for Box<[T]> -impl LockableAsMut for Vec { +impl LockableGetMut for Vec { type Inner<'a> = Box<[T::Inner<'a>]> where Self: 'a; - fn as_mut(&mut self) -> Self::Inner<'_> { - self.iter_mut().map(LockableAsMut::as_mut).collect() + fn get_mut(&mut self) -> Self::Inner<'_> { + self.iter_mut().map(LockableGetMut::get_mut).collect() } } @@ -571,7 +571,7 @@ mod tests { #[test] fn vec_as_mut() { let mut locks: Vec> = vec![Mutex::new(1), Mutex::new(2)]; - let lock_ptrs = LockableAsMut::as_mut(&mut locks); + let lock_ptrs = LockableGetMut::get_mut(&mut locks); assert_eq!(lock_ptrs.len(), 2); assert_eq!(*lock_ptrs[0], 1); @@ -621,7 +621,7 @@ mod tests { #[test] fn box_as_mut() { let mut locks: Box<[Mutex]> = vec![Mutex::new(1), Mutex::new(2)].into_boxed_slice(); - let lock_ptrs = LockableAsMut::as_mut(&mut locks); + let lock_ptrs = LockableGetMut::get_mut(&mut locks); assert_eq!(lock_ptrs.len(), 2); assert_eq!(*lock_ptrs[0], 1); -- cgit v1.2.3