@@ -30,7 +30,19 @@ pub struct Cluster {
3030 _worker_handle : RemoteHandle < ( ) > ,
3131}
3232
33- #[ derive( Clone ) ]
33+ /// Enables printing [Cluster] struct in a neat way, by skipping the rather useless
34+ /// print of channels state and printing [ClusterData] neatly.
35+ pub struct ClusterNeatDebug < ' a > ( pub & ' a Cluster ) ;
36+ impl < ' a > std:: fmt:: Debug for ClusterNeatDebug < ' a > {
37+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
38+ let cluster = self . 0 ;
39+ f. debug_struct ( "Cluster" )
40+ . field ( "data" , & ClusterDataNeatDebug ( & cluster. data . load ( ) ) )
41+ . finish_non_exhaustive ( )
42+ }
43+ }
44+
45+ #[ derive( Clone , Debug ) ]
3446pub struct Datacenter {
3547 pub nodes : Vec < Arc < Node > > ,
3648 pub rack_count : usize ,
@@ -45,6 +57,31 @@ pub struct ClusterData {
4557 pub ( crate ) datacenters : HashMap < String , Datacenter > ,
4658}
4759
60+ /// Enables printing [ClusterData] struct in a neat way, skipping the clutter involved by
61+ /// [ClusterData::ring] being large and [Self::keyspaces] debug print being very verbose by default.
62+ pub struct ClusterDataNeatDebug < ' a > ( pub & ' a Arc < ClusterData > ) ;
63+ impl < ' a > std:: fmt:: Debug for ClusterDataNeatDebug < ' a > {
64+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
65+ let cluster_data = & self . 0 ;
66+
67+ f. debug_struct ( "ClusterData" )
68+ . field ( "known_peers" , & cluster_data. known_peers )
69+ . field ( "ring" , {
70+ struct RingSizePrinter ( usize ) ;
71+ impl std:: fmt:: Debug for RingSizePrinter {
72+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
73+ write ! ( f, "<size={}>" , self . 0 )
74+ }
75+ }
76+ & RingSizePrinter ( cluster_data. ring . len ( ) )
77+ } )
78+ . field ( "keyspaces" , & cluster_data. keyspaces . keys ( ) )
79+ . field ( "all_nodes" , & cluster_data. all_nodes )
80+ . field ( "datacenters" , & cluster_data. datacenters )
81+ . finish_non_exhaustive ( )
82+ }
83+ }
84+
4885// Works in the background to keep the cluster updated
4986struct ClusterWorker {
5087 // Cluster data to keep updated:
0 commit comments