Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support display modifiers #13

Open
RagnarGrootKoerkamp opened this issue Jun 14, 2024 · 2 comments
Open

Support display modifiers #13

RagnarGrootKoerkamp opened this issue Jun 14, 2024 · 2 comments

Comments

@RagnarGrootKoerkamp
Copy link

Hey, thanks for the nice crate!

It would be great if you could add support for display modifiers, so that e.g. format!("{size:>10}") prints the value of the size with a total width of (at least) 10 characters, aligned to the right, and format!("{size:<10.3}") left-aligns the value and uses exactly 3 decimal places.

This is useful e.g. to display values in a column layout. In a perfect world something like below is what I'm looking for, but this may be a bit too much.

 1.0 B
 2.1kB
 4.0MB
12.2GB
@RagnarGrootKoerkamp
Copy link
Author

Oh nevermind, I see now that by default it already has exactly 3 significant digits. That's perfect! (Formatting the total width is easy by doing format!("{:>10}", format!("{size}").)

@mqudsi
Copy link
Member

mqudsi commented Jun 18, 2024

Hey, thanks for opening this issue.

There's a 0.6x branch with a new with_scale() option that can be used to explicitly set the number of decimal places that I'll merge into master after release 0.5 (and you can use it today), but that's not to be confused with width/precision (assuming that was what you intended).

If you don't mind, I'm going to re-open this issue because it would be interesting to see what native integration we can support with rust's format specifiers. It might end up going nowhere, but it doesn't mean we can't explore it and see. Perhaps we can translate a precision specifier like {:.N} into a call to with_scale(N) directly, which would be nice!

@mqudsi mqudsi reopened this Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants