From e9b577a0f52acff784445378d7ae4345b4adb683 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Sat, 27 Aug 2022 10:33:15 +0200 Subject: [PATCH] Make stdsync wrappers const-constructible --- src/stdsync.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/stdsync.rs b/src/stdsync.rs index c6e95f7..149caad 100644 --- a/src/stdsync.rs +++ b/src/stdsync.rs @@ -42,7 +42,6 @@ pub mod tracing { use crate::BorrowedMutex; use crate::LazyMutexId; - use crate::MutexId; /// Wrapper for [`std::sync::Mutex`]. /// @@ -51,7 +50,7 @@ pub mod tracing { #[derive(Debug, Default)] pub struct Mutex { inner: sync::Mutex, - id: MutexId, + id: LazyMutexId, } /// Wrapper for [`std::sync::MutexGuard`]. @@ -89,10 +88,10 @@ pub mod tracing { impl Mutex { /// Create a new tracing mutex with the provided value. - pub fn new(t: T) -> Self { + pub const fn new(t: T) -> Self { Self { inner: sync::Mutex::new(t), - id: MutexId::new(), + id: LazyMutexId::new(), } } @@ -220,8 +219,8 @@ pub mod tracing { impl Condvar { /// Creates a new condition variable which is ready to be waited on and notified. - pub fn new() -> Self { - Default::default() + pub const fn new() -> Self { + Self(sync::Condvar::new()) } /// Wrapper for [`std::sync::Condvar::wait`]. @@ -294,7 +293,7 @@ pub mod tracing { #[derive(Debug, Default)] pub struct RwLock { inner: sync::RwLock, - id: MutexId, + id: LazyMutexId, } /// Hybrid wrapper for both [`std::sync::RwLockReadGuard`] and [`std::sync::RwLockWriteGuard`]. @@ -312,10 +311,10 @@ pub mod tracing { pub type RwLockWriteGuard<'a, T> = TracingRwLockGuard<'a, sync::RwLockWriteGuard<'a, T>>; impl RwLock { - pub fn new(t: T) -> Self { + pub const fn new(t: T) -> Self { Self { inner: sync::RwLock::new(t), - id: MutexId::new(), + id: LazyMutexId::new(), } }