@@ -205,7 +205,7 @@ pub fn to_string(bytes: u64, si_prefix: bool) -> String {
205205
206206impl Display for ByteSize {
207207 fn fmt ( & self , f : & mut Formatter ) -> Result {
208- write ! ( f , "{}" , to_string( self . 0 , false ) )
208+ f . pad ( & to_string ( self . 0 , false ) )
209209 }
210210}
211211
@@ -318,6 +318,18 @@ mod tests {
318318 assert_display ( "609.0 PB" , ByteSize :: pb ( 609 ) ) ;
319319 }
320320
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+
321333 fn assert_to_string ( expected : & str , b : ByteSize , si : bool ) {
322334 assert_eq ! ( expected. to_string( ) , b. to_string_as( si) ) ;
323335 }
0 commit comments