diff options
| author | Mica White <botahamec@outlook.com> | 2024-03-13 16:50:37 -0400 |
|---|---|---|
| committer | Mica White <botahamec@outlook.com> | 2024-03-13 16:50:37 -0400 |
| commit | 603fa7a98ccedad0201164fa0b03c745d25b955b (patch) | |
| tree | fb74d9d91169af37f7082c39a352c6ae82fc7b5d /src/rwlock | |
| parent | b3fdc2cd2172cf946c79e255d4248e135c0d9669 (diff) | |
add Debug to WriteLock
Diffstat (limited to 'src/rwlock')
| -rw-r--r-- | src/rwlock/write_lock.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/rwlock/write_lock.rs b/src/rwlock/write_lock.rs index 0275a70..d7333ae 100644 --- a/src/rwlock/write_lock.rs +++ b/src/rwlock/write_lock.rs @@ -6,9 +6,25 @@ use crate::key::Keyable; use super::{RwLock, RwLockWriteGuard, RwLockWriteRef, WriteLock}; -impl<'a, T: ?Sized, R> Debug for WriteLock<'a, T, R> { +impl<'a, T: ?Sized + Debug, R: RawRwLock> Debug for WriteLock<'a, T, R> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(&format!("WriteLock<{}>", std::any::type_name::<T>())) + // safety: this is just a try lock, and the value is dropped + // immediately after, so there's no risk of blocking ourselves + // or any other threads + if let Some(value) = unsafe { self.try_lock_no_key() } { + f.debug_struct("WriteLock").field("data", &&*value).finish() + } else { + struct LockedPlaceholder; + impl Debug for LockedPlaceholder { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str("<locked>") + } + } + + f.debug_struct("ReadLock") + .field("data", &LockedPlaceholder) + .finish() + } } } |
