@@ -205,7 +205,7 @@ pub fn to_string(bytes: u64, si_prefix: bool) -> String {
205
205
206
206
impl Display for ByteSize {
207
207
fn fmt ( & self , f : & mut Formatter ) -> Result {
208
- write ! ( f , "{}" , to_string( self . 0 , false ) )
208
+ f . pad ( & to_string ( self . 0 , false ) )
209
209
}
210
210
}
211
211
@@ -318,6 +318,18 @@ mod tests {
318
318
assert_display ( "609.0 PB" , ByteSize :: pb ( 609 ) ) ;
319
319
}
320
320
321
+ #[ test]
322
+ fn test_display_alignment ( ) {
323
+ assert_eq ! ( "|357 B |" , format!( "|{:10}|" , ByteSize ( 357 ) ) ) ;
324
+ assert_eq ! ( "| 357 B|" , format!( "|{:>10}|" , ByteSize ( 357 ) ) ) ;
325
+ assert_eq ! ( "|357 B |" , format!( "|{:<10}|" , ByteSize ( 357 ) ) ) ;
326
+ assert_eq ! ( "| 357 B |" , format!( "|{:^10}|" , ByteSize ( 357 ) ) ) ;
327
+
328
+ assert_eq ! ( "|-----357 B|" , format!( "|{:->10}|" , ByteSize ( 357 ) ) ) ;
329
+ assert_eq ! ( "|357 B-----|" , format!( "|{:-<10}|" , ByteSize ( 357 ) ) ) ;
330
+ assert_eq ! ( "|--357 B---|" , format!( "|{:-^10}|" , ByteSize ( 357 ) ) ) ;
331
+ }
332
+
321
333
fn assert_to_string ( expected : & str , b : ByteSize , si : bool ) {
322
334
assert_eq ! ( expected. to_string( ) , b. to_string_as( si) ) ;
323
335
}
0 commit comments