diff --git a/src/sync.rs b/src/sync.rs index a551b9a..c936846 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -11,6 +11,7 @@ use std::alloc::Layout; use std::borrow::Borrow; use std::collections::BTreeMap; use std::collections::HashMap; +use std::fmt; use std::hash::Hash; use std::iter::{FromIterator, IntoIterator}; use std::ops::Index; @@ -27,6 +28,26 @@ pub struct FrozenMap { map: RwLock>, } +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); + }, + Err(TryLockError::WouldBlock) => { + struct LockedPlaceholder; + impl fmt::Debug for LockedPlaceholder { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("") + } + } + d.field("map", &LockedPlaceholder); + }, + } + d.finish_non_exhaustive() +} + impl Default for FrozenMap { fn default() -> Self { Self { @@ -387,6 +408,26 @@ pub struct FrozenVec { vec: RwLock>, } +impl fmt::Debug for FrozenVec { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let mut d = f.debug_struct("FrozenVec"); + match self.map.try_read() { + Ok(guard) => { + d.field("vec", &&*guard); + }, + Err(TryLockError::WouldBlock) => { + struct LockedPlaceholder; + impl fmt::Debug for LockedPlaceholder { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("") + } + } + d.field("vec", &LockedPlaceholder); + }, + } + d.finish_non_exhaustive() +} + impl FrozenVec { /// Returns the number of elements in the vector. pub fn len(&self) -> usize {