Skip to content

Conversation

@ChanTsune
Copy link
Contributor

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!

@ChanTsune
Copy link
Contributor Author

@robjtede I resolved conflict!

@robjtede
Copy link
Member

We'll chat about this approach once #69 is merged

@robjtede
Copy link
Member

robjtede commented Feb 13, 2025

I took inspiration from this and the cookie crate to come up with #76. I think it's more extensible to use a single type with an inner format selection vs distinct types with display impls.

Thank you for your contibution to the project 🎉 this has been a much needed feature request imo.

@robjtede robjtede closed this Feb 13, 2025
@ChanTsune ChanTsune deleted the feature/display branch February 14, 2025 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants