From eb7abc70eaf8c7a70a72f8db3e775c2947ddf566 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Sat, 8 May 2021 14:28:51 +0200 Subject: [PATCH] Derive Default more rather than implement it --- src/lib.rs | 6 ++++++ src/stdsync.rs | 17 ++++------------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1dbd923..13ca527 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -137,6 +137,12 @@ impl MutexId { } } +impl Default for MutexId { + fn default() -> Self { + Self::new() + } +} + impl fmt::Debug for MutexId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "MutexID({:?})", self.0) diff --git a/src/stdsync.rs b/src/stdsync.rs index d38bad6..41c1806 100644 --- a/src/stdsync.rs +++ b/src/stdsync.rs @@ -53,7 +53,7 @@ pub type DebugRwLock = RwLock; /// /// Refer to the [crate-level][`crate`] documentaiton for the differences between this struct and /// the one it wraps. -#[derive(Debug)] +#[derive(Debug, Default)] pub struct TracingMutex { inner: Mutex, id: MutexId, @@ -139,12 +139,6 @@ impl TracingMutex { } } -impl Default for TracingMutex { - fn default() -> Self { - Self::new(T::default()) - } -} - impl From for TracingMutex { fn from(t: T) -> Self { Self::new(t) @@ -241,12 +235,9 @@ impl TracingRwLock { } } -impl Default for TracingRwLock -where - T: Default, -{ - fn default() -> Self { - Self::new(T::default()) +impl From for TracingRwLock { + fn from(t: T) -> Self { + Self::new(t) } }