toml-rs / toml

Rust TOML Parser
https://docs.rs/toml
Apache License 2.0
729 stars 107 forks source link

How to avoid dotted subtables entirely? #809

Open fosskers opened 6 days ago

fosskers commented 6 days ago

Hi there. Currently naive calls to to_string_pretty yield output like:

[[foo]]
a = "a"

[foo.bar]
b = "b"

but I'd like it to output:

[[foo]]
a = "a"
bar = { b = "b" }

How can I accomplish this? I spent some time experimenting with DocumentMut but was unsuccessful. set_dotted seems like it might be what I want, but in practice it didn't appear to be. Am I overlooking something obvious?

Thank you.

epage commented 6 days ago

to_string_pretty errs on the side of making Tables when what you want is an InlineTable which is the default in some circumstances. To say much more, I'd need more context.

fosskers commented 5 days ago

I see that Table and InlineTable can be freely converted into one another. I'll try that.