-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Center alignment for fmt #16885
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
Center alignment for fmt #16885
Conversation
Python uses |
Good point, I wasn't aware of the python heritage. Changed it to '^' |
rt::AlignLeft => ( 0u, padding ), | ||
rt::AlignRight | rt::AlignUnknown => ( padding, 0u ), | ||
rt::AlignCenter => ( padding / 2, ( padding + 1 ) / 2 ), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stylistically we normally don't put spaces around the parens in tuples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Squashed the tuples down!
This looks like a solid implementation @wickerwaka, thanks! @P1start is right in that the design was influenced by python, so I think it makes sense to go ahead and implement this as well. |
The module docs should be updated as well: http://doc.rust-lang.org/std/fmt/#fill/alignment |
Use '^' to specify center alignment in format strings. fmt!( "[{:^5s}]", "Hi" ) -> "[ Hi ]" fmt!( "[{:^5s}]", "H" ) -> "[ H ]" fmt!( "[{:^5d}]", 1i ) -> "[ 1 ]" fmt!( "[{:^5d}]", -1i ) -> "[ -1 ]" fmt!( "[{:^6d}]", 1i ) -> "[ 1 ]" fmt!( "[{:^6d}]", -1i ) -> "[ -1 ]" If the padding is odd then the padding on the right will be one character longer than the padding on the left. Tuples squashed
cb6fff1
to
2bc4a5e
Compare
Use '^' to specify center alignment in format strings. ``` fmt!( "[{:^5s}]", "Hi" ) -> "[ Hi ]" fmt!( "[{:^5s}]", "H" ) -> "[ H ]" fmt!( "[{:^5d}]", 1i ) -> "[ 1 ]" fmt!( "[{:^5d}]", -1i ) -> "[ -1 ]" fmt!( "[{:^6d}]", 1i ) -> "[ 1 ]" fmt!( "[{:^6d}]", -1i ) -> "[ -1 ]" ``` If the padding is odd then the padding on the right will be one character longer than the padding on the left.
fix: Improve error recovery for match arms This should make use of the recovery token sets, but I think it'd be better to fix that as a whole while fixing the other places for these adhoc recovery checks.
Use '^' to specify center alignment in format strings.
If the padding is odd then the padding on the right will be one
character longer than the padding on the left.