refactor: subscription debug impls with type params
these help when logging, since we have limited number of subscription types.
This commit is contained in:
parent
fb6e80b954
commit
74a790400b
@ -7,12 +7,23 @@ use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SubscriptionRegistry<TReq: Debug + Eq + Hash, TRes: Debug> {
|
||||
subscriptions: HashMap<TReq, Arc<Mutex<Subscription<TRes>>>>,
|
||||
cancelled: bool,
|
||||
}
|
||||
|
||||
impl<TReq: Debug + Eq + Hash, TRes: Debug> fmt::Debug for SubscriptionRegistry<TReq, TRes> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
fmt,
|
||||
"{}<{}, {}>(subscriptions: {:?})",
|
||||
std::any::type_name::<Self>(),
|
||||
std::any::type_name::<TReq>(),
|
||||
std::any::type_name::<TRes>(),
|
||||
self.subscriptions)
|
||||
}
|
||||
}
|
||||
|
||||
impl<TReq: Debug + Eq + Hash, TRes: Debug> SubscriptionRegistry<TReq, TRes> {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
@ -102,13 +113,24 @@ impl fmt::Display for Cancelled {
|
||||
|
||||
impl std::error::Error for Cancelled {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Subscription<TResult> {
|
||||
result: Option<TResult>,
|
||||
wakers: Vec<Waker>,
|
||||
cancelled: bool,
|
||||
}
|
||||
|
||||
impl<TResult> fmt::Debug for Subscription<TResult> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
fmt,
|
||||
"Subscription<{}>(result: {}, wakers: {}, cancelled: {})",
|
||||
std::any::type_name::<TResult>(),
|
||||
if self.result.is_some() { "Some(_)" } else { "None" },
|
||||
self.wakers.len(),
|
||||
self.cancelled)
|
||||
}
|
||||
}
|
||||
|
||||
impl<TResult> Subscription<TResult> {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
Loading…
x
Reference in New Issue
Block a user