From 37ab873d21ca1fcd43db8d6a26d5bac4f5285f71 Mon Sep 17 00:00:00 2001 From: Mica White Date: Wed, 25 Dec 2024 17:58:06 -0500 Subject: Move some logic into the Sharable trait --- src/collection/boxed.rs | 14 +++++++------- src/collection/owned.rs | 20 ++++++++++---------- src/collection/ref.rs | 14 +++++++------- src/collection/retry.rs | 20 ++++++++++---------- 4 files changed, 34 insertions(+), 34 deletions(-) (limited to 'src/collection') diff --git a/src/collection/boxed.rs b/src/collection/boxed.rs index 6db0683..3766bed 100644 --- a/src/collection/boxed.rs +++ b/src/collection/boxed.rs @@ -62,11 +62,6 @@ unsafe impl Lockable for BoxedLockCollection { where Self: 'g; - type ReadGuard<'g> - = L::ReadGuard<'g> - where - Self: 'g; - fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>) { ptrs.extend(self.locks()) } @@ -74,14 +69,19 @@ unsafe impl Lockable for BoxedLockCollection { unsafe fn guard(&self) -> Self::Guard<'_> { self.data().guard() } +} + +unsafe impl Sharable for BoxedLockCollection { + type ReadGuard<'g> + = L::ReadGuard<'g> + where + Self: 'g; unsafe fn read_guard(&self) -> Self::ReadGuard<'_> { self.data().read_guard() } } -unsafe impl Sharable for BoxedLockCollection {} - unsafe impl OwnedLockable for BoxedLockCollection {} impl IntoIterator for BoxedLockCollection diff --git a/src/collection/owned.rs b/src/collection/owned.rs index 3ea08b5..714ff01 100644 --- a/src/collection/owned.rs +++ b/src/collection/owned.rs @@ -58,11 +58,6 @@ unsafe impl Lockable for OwnedLockCollection { where Self: 'g; - type ReadGuard<'g> - = L::ReadGuard<'g> - where - Self: 'g; - fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>) { self.data.get_ptrs(ptrs) } @@ -70,10 +65,6 @@ unsafe impl Lockable for OwnedLockCollection { unsafe fn guard(&self) -> Self::Guard<'_> { self.data.guard() } - - unsafe fn read_guard(&self) -> Self::ReadGuard<'_> { - self.data.read_guard() - } } impl LockableIntoInner for OwnedLockCollection { @@ -84,7 +75,16 @@ impl LockableIntoInner for OwnedLockCollection { } } -unsafe impl Sharable for OwnedLockCollection {} +unsafe impl Sharable for OwnedLockCollection { + type ReadGuard<'g> + = L::ReadGuard<'g> + where + Self: 'g; + + unsafe fn read_guard(&self) -> Self::ReadGuard<'_> { + self.data.read_guard() + } +} unsafe impl OwnedLockable for OwnedLockCollection {} diff --git a/src/collection/ref.rs b/src/collection/ref.rs index 9e07860..a9fc915 100644 --- a/src/collection/ref.rs +++ b/src/collection/ref.rs @@ -86,11 +86,6 @@ unsafe impl Lockable for RefLockCollection<'_, L> { where Self: 'g; - type ReadGuard<'g> - = L::ReadGuard<'g> - where - Self: 'g; - fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>) { ptrs.extend_from_slice(&self.locks); } @@ -98,14 +93,19 @@ unsafe impl Lockable for RefLockCollection<'_, L> { unsafe fn guard(&self) -> Self::Guard<'_> { self.data.guard() } +} + +unsafe impl Sharable for RefLockCollection<'_, L> { + type ReadGuard<'g> + = L::ReadGuard<'g> + where + Self: 'g; unsafe fn read_guard(&self) -> Self::ReadGuard<'_> { self.data.read_guard() } } -unsafe impl Sharable for RefLockCollection<'_, L> {} - impl Debug for RefLockCollection<'_, L> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct(stringify!(RefLockCollection)) diff --git a/src/collection/retry.rs b/src/collection/retry.rs index 42d86e5..0c44dea 100644 --- a/src/collection/retry.rs +++ b/src/collection/retry.rs @@ -219,11 +219,6 @@ unsafe impl Lockable for RetryingLockCollection { where Self: 'g; - type ReadGuard<'g> - = L::ReadGuard<'g> - where - Self: 'g; - fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>) { self.data.get_ptrs(ptrs) } @@ -231,10 +226,6 @@ unsafe impl Lockable for RetryingLockCollection { unsafe fn guard(&self) -> Self::Guard<'_> { self.data.guard() } - - unsafe fn read_guard(&self) -> Self::ReadGuard<'_> { - self.data.read_guard() - } } impl LockableAsMut for RetryingLockCollection { @@ -256,7 +247,16 @@ impl LockableIntoInner for RetryingLockCollection { } } -unsafe impl Sharable for RetryingLockCollection {} +unsafe impl Sharable for RetryingLockCollection { + type ReadGuard<'g> + = L::ReadGuard<'g> + where + Self: 'g; + + unsafe fn read_guard(&self) -> Self::ReadGuard<'_> { + self.data.read_guard() + } +} unsafe impl OwnedLockable for RetryingLockCollection {} -- cgit v1.2.3