Add more detailed Debug for MapSource (#56)

and everything it contains.

Stop short of printing all of the bytes in a State's VecDeque, but
expose most everything else for easier troubleshooting.
This commit is contained in:
Mike English 2023-08-28 15:14:15 -04:00 committed by GitHub
parent c53b3ddbe0
commit 5423d7c93a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 9 deletions

View File

@ -49,7 +49,7 @@ impl Deref for Publisher {
} }
} }
#[derive(Clone)] #[derive(Clone, Debug)]
pub struct Subscriber { pub struct Subscriber {
pub info: Arc<Info>, pub info: Arc<Info>,

View File

@ -51,7 +51,7 @@ impl fmt::Debug for Publisher {
} }
} }
#[derive(Clone)] #[derive(Clone, Debug)]
pub struct Subscriber { pub struct Subscriber {
pub name: String, pub name: String,
@ -72,12 +72,6 @@ impl Subscriber {
} }
} }
impl fmt::Debug for Subscriber {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "track subscriber: {:?}", self.name)
}
}
#[derive(Clone)] #[derive(Clone)]
pub struct Error { pub struct Error {
pub code: VarInt, pub code: VarInt,

View File

@ -1,3 +1,4 @@
use core::fmt;
use std::collections::VecDeque; use std::collections::VecDeque;
use tokio::sync::watch; use tokio::sync::watch;
@ -7,6 +8,18 @@ struct State<T> {
drained: usize, drained: usize,
} }
impl<T> fmt::Debug for State<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"State<{}> ( queue.len(): {}, drained: {} )",
std::any::type_name::<T>(),
&self.queue.len(),
&self.drained
)
}
}
impl<T> State<T> { impl<T> State<T> {
fn new() -> Self { fn new() -> Self {
Self { Self {
@ -85,7 +98,7 @@ impl<T: Clone> Default for Publisher<T> {
} }
} }
#[derive(Clone)] #[derive(Clone, Debug)]
pub struct Subscriber<T: Clone> { pub struct Subscriber<T: Clone> {
state: watch::Receiver<State<T>>, state: watch::Receiver<State<T>>,
index: usize, index: usize,