diff --git a/src/mutex_blocking.rs b/src/mutex_blocking.rs index bb18d9a..e3fa1f9 100644 --- a/src/mutex_blocking.rs +++ b/src/mutex_blocking.rs @@ -3,6 +3,7 @@ /// Multithreaded blocking Mutex pub mod sync { use std::{ + fmt, ops::{Deref, DerefMut}, sync::{Mutex as Inner, MutexGuard as InnerGuard}, }; @@ -10,6 +11,12 @@ pub mod sync { /// A multithreaded Mutex based on [`std::sync::Mutex`]. pub struct Mutex(Inner); + impl fmt::Debug for Mutex { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } + } + impl Mutex { /// Creates a new mutex in an unlocked state ready for use. pub const fn new(val: T) -> Self { @@ -43,6 +50,12 @@ pub mod sync { /// unlocked. pub struct MutexGuard<'a, T: ?Sized>(InnerGuard<'a, T>); + impl fmt::Debug for MutexGuard<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } + } + impl<'a, T: ?Sized> MutexGuard<'a, T> { /// Get the inner [`std::sync::MutexGuard`]. pub fn into_inner(self) -> InnerGuard<'a, T> { @@ -71,12 +84,19 @@ pub mod sync { pub mod unsync { use std::{ cell::{RefCell as Inner, RefMut as InnerGuard}, + fmt, ops::{Deref, DerefMut}, }; /// A singlethreaded Mutex based on [`std::cell::RefCell`]. pub struct Mutex(Inner); + impl fmt::Debug for Mutex { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } + } + impl Mutex { /// Creates a new mutex in an unlocked state ready for use. pub const fn new(val: T) -> Self { @@ -107,6 +127,12 @@ pub mod unsync { /// unlocked. pub struct MutexGuard<'a, T: ?Sized>(InnerGuard<'a, T>); + impl fmt::Debug for MutexGuard<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } + } + impl<'a, T: ?Sized> MutexGuard<'a, T> { /// Get the inner [`std::cell::RefMut`]. pub fn into_inner(self) -> InnerGuard<'a, T> {