bytesize
bytesize copied to clipboard
Added a more intuitive helper struct when printing ByteSize
The Display trait currently implemented in ByteSize only supports decimal prefixes.
If we want to use a binary prefix, we need to use ByteSize::to_string_as.
I have added helper some struct and methods to use them to ByteSize to make these more intuitive with refer to std::path::Path.
use bytesize::ByteSize;
assert_eq!("100 B", format!("{}", ByteSize::b(100).binary_display()));
assert_eq!("1.8 TiB", format!("{}", ByteSize::tb(2).binary_display()));
assert_eq!("100 B", format!("{}", ByteSize::b(100).decimal_display()));
assert_eq!("2.0 TB", format!("{}", ByteSize::tb(2).decimal_display()));
If you like this PR, it would be my pleasure if you merge it!