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

Derived Display doesn't handle width and alignment parameters #87

Closed
therustmonk opened this issue Feb 27, 2020 · 2 comments
Closed

Derived Display doesn't handle width and alignment parameters #87

therustmonk opened this issue Feb 27, 2020 · 2 comments

Comments

@therustmonk
Copy link

For struct like:

#[derive(Display)]
enum Type {
    One,
    Two,
}

The call:

println!("_ {:<20} _", Type::One);

Will print:

_ One _

But this expected:

_ One                 _

The workaround today only to convert it to string first:

println!("_ {:<20} _", Type::One.as_ref()); // and derive `AsRefStr` for enum needed
@Peternator7
Copy link
Owner

I didn't realize those parameters were exposed. Are you interested in working on this? If not, I'm going to mark this as help-wanted, and see if someone wants to fix it more quickly than I can get around to it.

For anyone interested in working on this. Display::fmt takes a Formatter argument that contains information about the requested padding and alignment. We need to add logic to read that and then pad the outputs accordingly before writing them.

@Peternator7
Copy link
Owner

I took a look into this over the weekend, and it's actually a pretty small fix. The fmt module exposes a method for formatting strings already so it was as easy as hooking into that. #95

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants