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

allow padding HumanBytes Display output #583

Closed
wants to merge 1 commit into from
Closed

allow padding HumanBytes Display output #583

wants to merge 1 commit into from

Conversation

darrell-roberts
Copy link

I've updated the Display implementation for HumanBytes so it can accept formatting parameters.

@djc
Copy link
Member

djc commented Sep 7, 2023

So what exactly is this trying to solve? It seems unfortunate that this will need an additional allocation.

@darrell-roberts
Copy link
Author

The goal was to be able to output HumanBytes with formatting parameters.

Ex:

#[test]
    fn test_human_bytes() {
        use std::fmt::Write;

        let mut s = String::new();
        write!(&mut s, "{:>10}", HumanBytes(10_000)).unwrap();
        assert_eq!(s, "  9.77 KiB");
    }

I agree though I would not want to incur an additional allocation cost. If there is a better alternative I'd go with that.

@darrell-roberts darrell-roberts closed this by deleting the head repository Mar 24, 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

Successfully merging this pull request may close these issues.

2 participants