5454use std:: {
5555 cell:: { Cell , RefCell } ,
5656 error:: Error ,
57- fmt:: Display ,
57+ fmt:: { Debug , Display } ,
5858 future:: Future ,
5959 pin:: Pin ,
6060 rc:: { Rc , Weak } ,
@@ -82,6 +82,16 @@ struct Inner {
8282 callbacks : RefCell < Slab < Box < dyn FnOnce ( ) > > > ,
8383}
8484
85+ impl Debug for Inner {
86+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
87+ f. debug_struct ( "Inner" )
88+ . field ( "cancelled" , & self . cancelled )
89+ . field ( "wakers.len" , & self . wakers . borrow ( ) . len ( ) )
90+ . field ( "callbacks.len" , & self . callbacks . borrow ( ) . len ( ) )
91+ . finish ( )
92+ }
93+ }
94+
8595/// A source that can cancel associated `CancellationToken`s.
8696///
8797/// Cancellation is **cooperative** and single-threaded. When cancelled:
@@ -100,7 +110,7 @@ struct Inner {
100110/// cts.cancel();
101111/// assert!(cts.is_cancelled());
102112/// ```
103- #[ derive( Default , Clone ) ]
113+ #[ derive( Debug , Default , Clone ) ]
104114pub struct CancellationTokenSource {
105115 inner : Rc < Inner > ,
106116}
@@ -125,13 +135,13 @@ pub struct CancellationTokenSource {
125135/// cts.cancel();
126136/// pool.run();
127137/// ```
128- #[ derive( Clone ) ]
138+ #[ derive( Debug , Clone ) ]
129139pub struct CancellationToken {
130140 inner : Rc < Inner > ,
131141}
132142
133143/// Error returned when a cancelled token is checked synchronously.
134- #[ derive( Copy , Clone , Debug , Default , Eq , Ord , PartialEq , PartialOrd , Hash ) ]
144+ #[ derive( Debug , Copy , Clone , Default , Eq , Ord , PartialEq , PartialOrd , Hash ) ]
135145pub struct Cancelled ;
136146
137147impl Display for Cancelled {
@@ -277,6 +287,7 @@ impl CancellationToken {
277287/// This ensures that callbacks are **only called once** and resources are cleaned up.
278288///
279289/// **Single-threaded only.** Not safe to use concurrently.
290+ #[ derive( Debug ) ]
280291pub struct CancellationTokenRegistration {
281292 inner : Weak < Inner > ,
282293 key : usize ,
@@ -301,6 +312,7 @@ impl Drop for CancellationTokenRegistration {
301312///
302313/// **Single-threaded only.** Not Send or Sync.
303314/// The future will be woken exactly once when the token is cancelled.
315+ #[ derive( Debug ) ]
304316pub struct CancelledFuture {
305317 token : CancellationToken ,
306318}
0 commit comments