-
-
Notifications
You must be signed in to change notification settings - Fork 282
formatting with alignment fails #98
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
Comments
To be exact, it is a common behavior that formatting implementations discard the width and alignment information: fn main() {
println!("{:>11?}", "a\nb\nc"); // not aligned
println!("{:>11}", format!("{:?}", "a\nb\nc")); // aligned
} I would argue that this behavior is, while frustrating, justifiable because alignment requires the length of printed string beforehand and this might not be acceptable for many types. (For the case of |
If a type does not support alignment, then |
Yes @lifthrasiir is right in that most types do not support the width/alignment of the underlying formatting system, and the best solution to this (as you've found) is to call |
Poop. Ok, that was really frustrating. Maybe a warning? A warning would have saved a lot of angst.
Where can I submit a PR for that? |
Unfortunately there's no way for the formatting infrastructure to know whether a type actually looks at the formatting flags or not (as it's all trait-based).
A PR editing this file should do the trick! |
Padding and alignment are often not implemented by types and can cause confusion in the user. Per discussion with @alexcrichton, here is my PR. /cc time-rs/time#98
hey, I'm learning rust and re-writing a very basic
cal
in order to learn. ran into a strange formatting bug:know what's going on here? i don't think i should have to call
.to_string()
in order to get the alignment...?The text was updated successfully, but these errors were encountered: