@@ -11,7 +11,7 @@ use crate::{
1111 reporter:: { ErrorOnlyReporter , ErrorReport , ProgressAndErrorReporter , ProgressReport } ,
1212 runtime_error:: RuntimeError ,
1313 size,
14- visualizer:: { BarAlignment , Direction , Visualizer } ,
14+ visualizer:: { BarAlignment , ColumnWidthDistribution , Direction , Visualizer } ,
1515} ;
1616use clap:: Parser ;
1717use hdd:: any_path_is_in_hdd;
@@ -67,16 +67,22 @@ impl App {
6767 . map_err ( RuntimeError :: DeserializationFailure ) ?
6868 . body ;
6969
70- macro_rules! extract {
71- ( $tree: expr, $bytes_format: expr) => { {
72- let JsonTree { tree, shared } = $tree;
70+ trait VisualizeJsonTree : size:: Size + Into < u64 > + Send {
71+ fn visualize_json_tree (
72+ tree : JsonTree < Self > ,
73+ bytes_format : Self :: DisplayFormat ,
74+ column_width_distribution : ColumnWidthDistribution ,
75+ direction : Direction ,
76+ bar_alignment : BarAlignment ,
77+ ) -> Result < String , RuntimeError > {
78+ let JsonTree { tree, shared } = tree;
7379
7480 let data_tree = tree
7581 . par_try_into_tree ( )
7682 . map_err ( |error| RuntimeError :: InvalidInputReflection ( error. to_string ( ) ) ) ?;
7783 let visualizer = Visualizer {
7884 data_tree : & data_tree,
79- bytes_format: $bytes_format ,
85+ bytes_format,
8086 column_width_distribution,
8187 direction,
8288 bar_alignment,
@@ -85,20 +91,36 @@ impl App {
8591 let JsonShared { details, summary } = shared;
8692 let summary = summary. or_else ( || details. map ( |details| details. summarize ( ) ) ) ;
8793
88- if let Some ( summary) = summary {
89- let summary = summary. display( $ bytes_format) ;
94+ let visualization = if let Some ( summary) = summary {
95+ let summary = summary. display ( bytes_format) ;
9096 // visualizer already ends with "\n"
9197 format ! ( "{visualizer}{summary}\n " )
9298 } else {
9399 visualizer. to_string ( )
94- }
95- } } ;
100+ } ;
101+
102+ Ok ( visualization)
103+ }
104+ }
105+
106+ impl < Size : size:: Size + Into < u64 > + Send > VisualizeJsonTree for Size { }
107+
108+ macro_rules! visualize {
109+ ( $tree: expr, $bytes_format: expr) => {
110+ VisualizeJsonTree :: visualize_json_tree(
111+ $tree,
112+ $bytes_format,
113+ column_width_distribution,
114+ direction,
115+ bar_alignment,
116+ )
117+ } ;
96118 }
97119
98120 let visualization = match body {
99- JsonDataBody :: Bytes ( tree) => extract ! ( tree, bytes_format) ,
100- JsonDataBody :: Blocks ( tree) => extract ! ( tree, ( ) ) ,
101- } ;
121+ JsonDataBody :: Bytes ( tree) => visualize ! ( tree, bytes_format) ,
122+ JsonDataBody :: Blocks ( tree) => visualize ! ( tree, ( ) ) ,
123+ } ? ;
102124
103125 print ! ( "{visualization}" ) ; // it already ends with "\n", println! isn't needed here.
104126 return Ok ( ( ) ) ;
0 commit comments