[Debug Trait] signaling.rs

This commit is contained in:
Poly 2021-02-10 03:22:37 +01:00
parent f6a63d351d
commit bb90631d65
1 changed files with 13 additions and 0 deletions

View File

@ -21,10 +21,12 @@ use std::{
any::Any, any::Any,
cell::RefCell, cell::RefCell,
collections::VecDeque, collections::VecDeque,
fmt,
rc::{Rc, Weak}, rc::{Rc, Weak},
}; };
/// A signaler, main type for signaling /// A signaler, main type for signaling
#[derive(Debug)]
pub struct Signaler<S> { pub struct Signaler<S> {
inner: Rc<SignalInner<S>>, inner: Rc<SignalInner<S>>,
} }
@ -88,6 +90,7 @@ impl<S> Default for Signaler<S> {
/// Dropping it will disable and drop the callback it is associated to. /// Dropping it will disable and drop the callback it is associated to.
/// If you don't plan to ever disable the callback, you can use the `leak` /// If you don't plan to ever disable the callback, you can use the `leak`
/// method to safely get rid of this value. /// method to safely get rid of this value.
#[derive(Debug)]
pub struct SignalToken { pub struct SignalToken {
signal: Rc<dyn Any>, signal: Rc<dyn Any>,
} }
@ -108,6 +111,16 @@ struct SignalInner<S> {
pending_events: RefCell<VecDeque<S>>, pending_events: RefCell<VecDeque<S>>,
} }
impl<S: fmt::Debug> fmt::Debug for SignalInner<S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("SignalInner")
.field("callbacks::len()", &self.callbacks.borrow().len())
.field("pending_callbacks::len()", &self.pending_callbacks.borrow().len())
.field("pending_events", &self.pending_events)
.finish()
}
}
impl<S> SignalInner<S> { impl<S> SignalInner<S> {
fn new() -> SignalInner<S> { fn new() -> SignalInner<S> {
SignalInner { SignalInner {