From df0f28b386af2d48e2d9260162c30852d4550318 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Sun, 31 Aug 2025 12:56:49 +0200 Subject: [PATCH] Relax sized bounds for std::sync wrappers --- CHANGELOG.md | 4 ++++ src/stdsync/tracing.rs | 38 +++++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a9c36b..636bafb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed + +- `std::sync` wrappers now no longer incorrectly require `T: Sized` + ## [0.3.1] ### Added diff --git a/src/stdsync/tracing.rs b/src/stdsync/tracing.rs index fe20bce..ccbaa6c 100644 --- a/src/stdsync/tracing.rs +++ b/src/stdsync/tracing.rs @@ -25,9 +25,9 @@ mod lazy_lock; /// Refer to the [crate-level][`crate`] documentation for the differences between this struct and /// the one it wraps. #[derive(Debug, Default)] -pub struct Mutex { - inner: sync::Mutex, +pub struct Mutex { id: LazyMutexId, + inner: sync::Mutex, } /// Wrapper for [`std::sync::MutexGuard`]. @@ -35,7 +35,7 @@ pub struct Mutex { /// Refer to the [crate-level][`crate`] documentation for the differences between this struct and /// the one it wraps. #[derive(Debug)] -pub struct MutexGuard<'a, T> { +pub struct MutexGuard<'a, T: ?Sized> { inner: sync::MutexGuard<'a, T>, _mutex: BorrowedMutex<'a>, } @@ -71,7 +71,9 @@ impl Mutex { id: LazyMutexId::new(), } } +} +impl Mutex { /// Wrapper for [`std::sync::Mutex::lock`]. /// /// # Panics @@ -123,12 +125,15 @@ impl Mutex { } /// Unwrap the mutex and return its inner value. - pub fn into_inner(self) -> LockResult { + pub fn into_inner(self) -> LockResult + where + T: Sized, + { self.inner.into_inner() } } -impl PrivateTraced for Mutex { +impl PrivateTraced for Mutex { fn get_id(&self) -> &crate::MutexId { &self.id } @@ -140,7 +145,7 @@ impl From for Mutex { } } -impl Deref for MutexGuard<'_, T> { +impl Deref for MutexGuard<'_, T> { type Target = T; fn deref(&self) -> &Self::Target { @@ -148,13 +153,13 @@ impl Deref for MutexGuard<'_, T> { } } -impl DerefMut for MutexGuard<'_, T> { +impl DerefMut for MutexGuard<'_, T> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.inner } } -impl fmt::Display for MutexGuard<'_, T> { +impl fmt::Display for MutexGuard<'_, T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.inner.fmt(f) } @@ -274,9 +279,9 @@ impl Condvar { /// Wrapper for [`std::sync::RwLock`]. #[derive(Debug, Default)] -pub struct RwLock { - inner: sync::RwLock, +pub struct RwLock { id: LazyMutexId, + inner: sync::RwLock, } /// Hybrid wrapper for both [`std::sync::RwLockReadGuard`] and [`std::sync::RwLockWriteGuard`]. @@ -300,7 +305,9 @@ impl RwLock { id: LazyMutexId::new(), } } +} +impl RwLock { /// Wrapper for [`std::sync::RwLock::read`]. /// /// # Panics @@ -377,12 +384,15 @@ impl RwLock { } /// Unwrap the mutex and return its inner value. - pub fn into_inner(self) -> LockResult { + pub fn into_inner(self) -> LockResult + where + T: Sized, + { self.inner.into_inner() } } -impl PrivateTraced for RwLock { +impl PrivateTraced for RwLock { fn get_id(&self) -> &crate::MutexId { &self.id } @@ -396,6 +406,7 @@ impl From for RwLock { impl Deref for TracingRwLockGuard<'_, L> where + T: ?Sized, L: Deref, { type Target = T; @@ -405,8 +416,9 @@ where } } -impl DerefMut for TracingRwLockGuard<'_, L> +impl DerefMut for TracingRwLockGuard<'_, L> where + T: ?Sized, L: Deref + DerefMut, { fn deref_mut(&mut self) -> &mut Self::Target {