From f2fac5b0fa2f192cc5691ce4a38d37dd9387ba32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Mon, 9 Oct 2023 10:26:44 -0400 Subject: [PATCH] refactor: Refactor debug implementations in sync.rs - Replaces the `debug_struct` method with straight `debug_map` for `FrozenMap` and `debug_list` for `FrozenVec` - Simplifies error handling by moving to `f.debug_tuple()` method instead of the previous `field()` calls based on `DebugStruct` --- src/sync.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/sync.rs b/src/sync.rs index 467ce05..010b506 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -31,13 +31,12 @@ pub struct FrozenMap { impl fmt::Debug for FrozenMap { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let mut d = f.debug_struct("FrozenMap"); match self.map.try_read() { Ok(guard) => { - d.field("map", &&*guard); + f.debug_map().entries(guard.iter()).finish() }, Err(TryLockError::Poisoned(err)) => { - d.field("map", &&**err.get_ref()); + f.debug_tuple("FrozenMap").field(&&**err.get_ref()).finish() } Err(TryLockError::WouldBlock) => { struct LockedPlaceholder; @@ -46,10 +45,9 @@ impl fmt::Debug for FrozenMap { f.write_str("") } } - d.field("map", &LockedPlaceholder); + f.debug_tuple("FrozenMap").field(&LockedPlaceholder).finish() }, } - d.finish_non_exhaustive() } } @@ -415,13 +413,12 @@ pub struct FrozenVec { impl fmt::Debug for FrozenVec { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let mut d = f.debug_struct("FrozenVec"); match self.vec.try_read() { Ok(guard) => { - d.field("vec", &&*guard); + f.debug_list().entries(guard.iter()).finish() }, Err(TryLockError::Poisoned(err)) => { - d.field("vec", &&**err.get_ref()); + f.debug_tuple("FrozenMap").field(&&**err.get_ref()).finish() } Err(TryLockError::WouldBlock) => { struct LockedPlaceholder; @@ -430,10 +427,9 @@ impl fmt::Debug for FrozenVec { f.write_str("") } } - d.field("vec", &LockedPlaceholder); + f.debug_tuple("FrozenMap").field(&LockedPlaceholder).finish() }, } - d.finish_non_exhaustive() } }