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

Make Array of Tables inlined by default when using to_string_pretty #662

Open
wiiznokes opened this issue Dec 11, 2023 · 5 comments
Open
Labels
A-serde Area: Serde integration C-question Uncertainty is involved

Comments

@wiiznokes
Copy link

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.

@epage epage added A-serde Area: Serde integration C-question Uncertainty is involved labels Dec 11, 2023
@epage
Copy link
Member

epage commented Dec 11, 2023

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.

@wiiznokes
Copy link
Author

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.

@epage
Copy link
Member

epage commented Dec 11, 2023

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.

@wiiznokes
Copy link
Author

"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.

@epage
Copy link
Member

epage commented Dec 11, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-serde Area: Serde integration C-question Uncertainty is involved
Projects
None yet
Development

No branches or pull requests

2 participants