@@ -9,10 +9,10 @@ use std::{
9
9
use crate :: {
10
10
messages:: MessageLevel ,
11
11
progress:: { Id , Step , StepShared } ,
12
- Progress , Unit ,
12
+ Count , NestedProgress , Progress , Unit ,
13
13
} ;
14
14
15
- /// A [`Progress `] implementation which displays progress as it happens without the use of a renderer.
15
+ /// A [`NestedProgress `] implementation which displays progress as it happens without the use of a renderer.
16
16
///
17
17
/// Note that this incurs considerable performance cost as each progress calls ends up getting the system time
18
18
/// to see if progress information should actually be emitted.
@@ -73,36 +73,31 @@ impl Log {
73
73
}
74
74
}
75
75
76
- impl Progress for Log {
77
- type SubProgress = Log ;
76
+ impl Count for Log {
77
+ fn set ( & self , step : Step ) {
78
+ self . step . store ( step, Ordering :: SeqCst ) ;
79
+ self . maybe_log ( )
80
+ }
78
81
79
- fn add_child ( & mut self , name : impl Into < String > ) -> Self :: SubProgress {
80
- self . add_child_with_id ( name , crate :: progress :: UNKNOWN )
82
+ fn step ( & self ) -> usize {
83
+ self . step . load ( Ordering :: Relaxed )
81
84
}
82
85
83
- fn add_child_with_id ( & mut self , name : impl Into < String > , id : Id ) -> Self :: SubProgress {
84
- Log {
85
- name : format ! ( "{}{}{}" , self . name, SEP , Into :: <String >:: into( name) ) ,
86
- id,
87
- current_level : self . current_level + 1 ,
88
- max_level : self . max_level ,
89
- step : Default :: default ( ) ,
90
- max : None ,
91
- unit : None ,
92
- trigger : Arc :: clone ( & self . trigger ) ,
93
- }
86
+ fn inc_by ( & self , step : Step ) {
87
+ self . step . fetch_add ( step, Ordering :: SeqCst ) ;
88
+ self . maybe_log ( )
94
89
}
95
90
91
+ fn counter ( & self ) -> Option < StepShared > {
92
+ Some ( self . step . clone ( ) )
93
+ }
94
+ }
95
+
96
+ impl Progress for Log {
96
97
fn init ( & mut self , max : Option < Step > , unit : Option < Unit > ) {
97
98
self . max = max;
98
99
self . unit = unit;
99
100
}
100
-
101
- fn set ( & mut self , step : Step ) {
102
- self . step . store ( step, Ordering :: SeqCst ) ;
103
- self . maybe_log ( )
104
- }
105
-
106
101
fn unit ( & self ) -> Option < Unit > {
107
102
self . unit . clone ( )
108
103
}
@@ -117,17 +112,7 @@ impl Progress for Log {
117
112
prev
118
113
}
119
114
120
- fn step ( & self ) -> usize {
121
- self . step . load ( Ordering :: Relaxed )
122
- }
123
-
124
- fn inc_by ( & mut self , step : Step ) {
125
- self . step . fetch_add ( step, Ordering :: SeqCst ) ;
126
- self . maybe_log ( )
127
- }
128
-
129
- fn set_name ( & mut self , name : impl Into < String > ) {
130
- let name = name. into ( ) ;
115
+ fn set_name ( & mut self , name : String ) {
131
116
self . name = self
132
117
. name
133
118
. split ( "::" )
@@ -144,16 +129,32 @@ impl Progress for Log {
144
129
self . id
145
130
}
146
131
147
- fn message ( & self , level : MessageLevel , message : impl Into < String > ) {
148
- let message: String = message. into ( ) ;
132
+ fn message ( & self , level : MessageLevel , message : String ) {
149
133
match level {
150
134
MessageLevel :: Info => log:: info!( "ℹ{} → {}" , self . name, message) ,
151
135
MessageLevel :: Failure => log:: error!( "𐄂{} → {}" , self . name, message) ,
152
136
MessageLevel :: Success => log:: info!( "✓{} → {}" , self . name, message) ,
153
137
}
154
138
}
139
+ }
155
140
156
- fn counter ( & self ) -> Option < StepShared > {
157
- Some ( self . step . clone ( ) )
141
+ impl NestedProgress for Log {
142
+ type SubProgress = Log ;
143
+
144
+ fn add_child ( & mut self , name : impl Into < String > ) -> Self :: SubProgress {
145
+ self . add_child_with_id ( name, crate :: progress:: UNKNOWN )
146
+ }
147
+
148
+ fn add_child_with_id ( & mut self , name : impl Into < String > , id : Id ) -> Self :: SubProgress {
149
+ Log {
150
+ name : format ! ( "{}{}{}" , self . name, SEP , Into :: <String >:: into( name) ) ,
151
+ id,
152
+ current_level : self . current_level + 1 ,
153
+ max_level : self . max_level ,
154
+ step : Default :: default ( ) ,
155
+ max : None ,
156
+ unit : None ,
157
+ trigger : Arc :: clone ( & self . trigger ) ,
158
+ }
158
159
}
159
160
}
0 commit comments