11use crate :: tree:: ProgressStep ;
2- use std:: fmt:: Write ;
3- use std:: { fmt, ops:: Deref } ;
2+ use std:: { fmt, fmt:: Write , ops:: Deref } ;
3+
4+ #[ cfg( feature = "unit-bytes" ) ]
5+ mod bytes;
6+ #[ cfg( feature = "unit-bytes" ) ]
7+ pub use bytes:: Bytes ;
48
59pub trait DisplayValue {
610 fn display_current_value (
711 & self ,
812 f : & mut fmt:: Formatter ,
913 value : ProgressStep ,
10- _max : Option < ProgressStep > ,
14+ _upper : Option < ProgressStep > ,
1115 ) -> fmt:: Result {
1216 write ! ( f, "{}" , value)
1317 }
14- fn display_upper_bound ( & self , f : & mut fmt:: Formatter , value : ProgressStep ) -> fmt:: Result {
15- write ! ( f, "{}" , value)
18+ fn display_upper_bound (
19+ & self ,
20+ f : & mut fmt:: Formatter ,
21+ upper_bound : ProgressStep ,
22+ _value : ProgressStep ,
23+ ) -> fmt:: Result {
24+ write ! ( f, "{}" , upper_bound)
1625 }
1726 fn display_unit ( & self , f : & mut fmt:: Formatter , value : ProgressStep ) -> fmt:: Result ;
1827 fn display_percentage ( & self , f : & mut fmt:: Formatter , percentage : f64 ) -> fmt:: Result {
@@ -39,6 +48,12 @@ impl Unit {
3948 pub fn label_and_mode ( label : & ' static str , mode : Mode ) -> Self {
4049 Unit :: Label ( label, Some ( mode) )
4150 }
51+ pub fn dynamic ( label : impl DisplayValue + ' static ) -> Self {
52+ Unit :: Dynamic ( Box :: new ( label) , None )
53+ }
54+ pub fn dynamic_and_mode ( label : impl DisplayValue + ' static , mode : Mode ) -> Self {
55+ Unit :: Dynamic ( Box :: new ( label) , Some ( mode) )
56+ }
4257}
4358
4459/// Display and utilities
@@ -121,13 +136,13 @@ impl<'a> fmt::Display for UnitDisplay<'a> {
121136 unit. display_current_value ( f, self . current_value , self . upper_bound ) ?;
122137 if let Some ( upper) = self . upper_bound {
123138 f. write_char ( '/' ) ?;
124- unit. display_upper_bound ( f, upper) ?;
125- }
126- if self . display . unit ( ) {
127- f. write_char ( ' ' ) ?;
139+ unit. display_upper_bound ( f, upper, self . current_value ) ?;
128140 }
129141 }
130142 if self . display . unit ( ) {
143+ if self . display . values ( ) {
144+ f. write_char ( ' ' ) ?;
145+ }
131146 unit. display_unit ( f, self . current_value ) ?;
132147
133148 if let Some ( ( Mode :: PercentageAfterUnit , fraction) ) = mode_and_fraction {
0 commit comments