m: Update fmt::Debug to produce useful output

cc #86, it's harder to get this info on no_std so I've ignored it for
now

Signed-off-by: John Nunley <dev@notgull.net>
This commit is contained in:
John Nunley 2024-04-13 21:10:52 -07:00
parent 99078d12ec
commit 7bc92d7e83
No known key found for this signature in database
GPG Key ID: 2FE69973CFD64832
1 changed files with 26 additions and 2 deletions

View File

@ -87,7 +87,7 @@ use std::ops::{Deref, DerefMut};
use std::panic::{RefUnwindSafe, UnwindSafe};
use std::pin::Pin;
use std::ptr::{self, NonNull};
use std::sync::{Mutex, MutexGuard};
use std::sync::{Mutex, MutexGuard, TryLockError};
use std::task::{Context, Poll, Waker};
use std::thread::{self, Thread};
use std::time::{Duration, Instant};
@ -577,7 +577,31 @@ impl<T> Drop for Event<T> {
impl fmt::Debug for Event {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad("Event { .. }")
let inner = match self.try_inner() {
None => return f
.debug_tuple("Event")
.field(&format_args!("<uninitialized>"))
.finish(),
Some(inner) => inner
};
let guard = match inner.list.try_lock() {
Err(TryLockError::WouldBlock) => {
return f
.debug_tuple("Event")
.field(&format_args!("<locked>"))
.finish()
}
Err(TryLockError::Poisoned(err)) => err.into_inner(),
Ok(lock) => lock,
};
f.debug_struct("Event")
.field("listeners_notified", &guard.notified)
.field("listeners_total", &guard.len)
.finish()
}
}