-
Notifications
You must be signed in to change notification settings - Fork 1.6k
pretty print Debug
of tuples, tuple structs and enum variants in a single line
#1198
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
Conversation
…single line Currently, `println!("{:#?}", Some(1));` *pretty* print output as, with newlines and indent: ``` Some( 1 ) ``` I don't think it is **pretty** print: it's weird and ugly, no one write code like this. It is not a preferred code style also. `Some(1)` itself, without adding newlines and indent, is pretty well. Tuples were already implemented, in 1.0 stable, to pretty print in a single line, without adding newlines and indents. So we should do the same for tuple structs and enum variants, for consistency.
what if you have a type in the tuple that is printed in multiple lines? |
This RFC doesn't change that behavior. Tuples were printed in a single line
|
Perhaps pretty-printing should keeps more than one thing on the same line up to 80 characters or os. Python’s |
As I noted in the related PR rust-lang/rust#26874,
MyTupleStruct(MyStruct {
a: 1,
b: TupleStruct(MyOtherStruct {
foo: bar
}, 10, "hi", Thing {
baz: buzz
})
}, true, false, OtherStruct {
thing: "hi"
}) An adaptive scheme like @SimonSapin's suggestion would be possible but a bit tricky since this stuff can't allocate. You could do it by pretty-printing fields first into a line and character counting |
I'm fine as it is, I'm unsure if we can insert any adaptive behavior without redirecting inner #Debug outputs to a intermediate buffer (which one may argue is a nonstarter). |
I'm in favor of this since I ran into issues with debug printing myself (with code similar to this: http://is.gd/xbWb2l) The output is either an unreadable oneliner (at least with many opcodes):
or this bloated mess:
The proposed solution would make this look similar to the |
This RFC is entering its final comment period. |
I agree with @sfackler that this rule would hurt readability in many non-trivial cases. I do not think that making these trivial cases more natural to read justifies making more complex types (in my opinion) much harder to read. Counting line lengths would not even solve this issue, and also add a lot more complexity. |
The @rust-lang/libs team has decided that, while there is something to be said for improving the readability of Debug output, the changes proposed in this PR do not address that issue sufficiently:
An adaptive scheme could be interesting, but will need a lot of work to figure out what we actually mean by "pretty print". |
Currently,
println!("{:#?}", Some(1));
pretty print output as, with newlines and indent:But I don't think it is pretty print: it's weird and ugly, no one write code like this. It is not a preferred code style also.
Some(1)
itself, without adding newlines and indent, is pretty well.Tuples were already implemented, in 1.0 stable, to pretty print in a single line, without adding newlines and indents. So we should do the same for tuple structs and enum variants, for consistency.