Skip to content

Commit

Permalink
Merge pull request #423 from ldm0/simple_debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanieu authored Dec 5, 2023
2 parents 311e7e1 + 2795355 commit adbad82
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions lock_api/src/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1198,21 +1198,15 @@ impl<R: RawRwLock, T> From<T> for RwLock<R, T> {

impl<R: RawRwLock, T: ?Sized + fmt::Debug> fmt::Debug for RwLock<R, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut d = f.debug_struct("RwLock");
match self.try_read() {
Some(guard) => f.debug_struct("RwLock").field("data", &&*guard).finish(),
Some(guard) => d.field("data", &&*guard),
None => {
struct LockedPlaceholder;
impl fmt::Debug for LockedPlaceholder {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("<locked>")
}
}

f.debug_struct("RwLock")
.field("data", &LockedPlaceholder)
.finish()
// Additional format_args! here is to remove quotes around <locked> in debug output.
d.field("data", &format_args!("<locked>"))
}
}
};
d.finish()
}
}

Expand Down

0 comments on commit adbad82

Please sign in to comment.