toml
toml copied to clipboard
Make Array of Tables inlined by default when using to_string_pretty
I would expect to be the case because the docs says it is the preferred way when appropriate: https://toml.io/en/v1.0.0#filename-extension.
I guess what they mean by that, is when the table has not to many fields or when the lines don't get to long.
I would expect to be the case because the docs says it is the preferred way when appropriate:
I'm somehow overlooking where it says that.
I guess what they mean by that, is when the table has not to many fields or when the lines don't get to long.
Currently, we don't do very deep introspection for our formatting choices. Not too keen to do so now, especially since we offer toml_edit for if you want things highly customized. Arrays of tables are also a bit of an odd case in terms of being awkward to work with no matter what syntax is used.
I'm somehow overlooking where it says that.
It just suggests it indeed. My point is just that is my sens, it's more "pretty" to write
coord = [
{ x = 1, y = 2 },
{ x = 3, y = 4 },
]
instead of
[[coord]]
x = 1
y = 2
[[coord]]
x = 3
y = 4
so it should be made the default. Maybe based only on the number of fields, as i said.
It just suggests it indeed.
Could you quote or screenshot the section? The anchor provided was for file extensions. Just above that I see a reference comparing the two but it only says "You may also use inline tables where appropriate" which does not say one is preferred over the other.
As for which is "prettier", a lot of that comes down to the person and the use case.
"You may also use inline tables where appropriate"
That seems like a suggestion to me. That why in my sens, this crate should try to define "appropriate" and use inline table when it make sens.
As for which is "prettier", a lot of that comes down to the person and the use case.
Agreed but in this case, we can clearly see that one use 4 lines and the other 7. Also, [[coord]] is repeated 2 times in the second one.
In terms of Rust code, is feel intuitive to write it this way:
struct Wrapper {
coords: Vec<Coord>, // notice the 's'
}
and then have:
# this is intuitive
coords = [
{ x = 1, y = 2 },
{ x = 3, y = 4 },
]
# defining multiple time coords with an 's' seems odd to me
[[coords]]
x = 1
y = 2
[[coords]]
x = 3
y = 4
But that debatable.
That seems like a suggestion to me. That why in my sens, this crate should try to define "appropriate" and use inline table when it make sens.
I would re-phrase that line as "as an alternative, you can also use inline tables where it makes sense". That is very different than "you should prefer inline tables where appropriate"
To put this in context, things the TOML spec discourages
- empty keys
- putting tables out of order
- arbitrary placement of
_between numbers - splitting inline tables across lines