mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-21 00:00:10 +02:00
sync: improve Debug impl for RwLock (#5647)
This commit is contained in:
@@ -85,7 +85,6 @@ const MAX_READS: u32 = 10;
|
||||
/// [`RwLockWriteGuard`]: struct@RwLockWriteGuard
|
||||
/// [`Send`]: trait@std::marker::Send
|
||||
/// [_write-preferring_]: https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock#Priority_policies
|
||||
#[derive(Debug)]
|
||||
pub struct RwLock<T: ?Sized> {
|
||||
#[cfg(all(tokio_unstable, feature = "tracing"))]
|
||||
resource_span: tracing::Span,
|
||||
@@ -1095,3 +1094,17 @@ where
|
||||
Self::new(T::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ?Sized> std::fmt::Debug for RwLock<T>
|
||||
where
|
||||
T: std::fmt::Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let mut d = f.debug_struct("RwLock");
|
||||
match self.try_read() {
|
||||
Ok(inner) => d.field("data", &&*inner),
|
||||
Err(_) => d.field("data", &format_args!("<locked>")),
|
||||
};
|
||||
d.finish()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user