3 ms·
I like TOML too, but speaking of footguns, there is one where it comes to serialization. If you have something like: struct Foo { int bar;
by Arnavion 6y ago
I like TOML too, but speaking of footguns, there is one where it comes to serialization. If you have something like:
struct Foo {
int bar;
Baz baz;
int quux;
}
... you can't naively serialize this like:
[foo]
bar = 5
[foo.baz]
...
quux = 6
because that makes `quux` a property of `foo.baz`, not of `foo`.
The serializer has to be smart enough to recognize that primitive fields have to be serialized before object fields. As a practical example, Rust's TOML library is not smart enough to do so, though it does at least detect when this would happen and fails with a runtime error. (The workaround is to change your type definition to reorder the fields yourself.)
Ref: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=dbc26ca3f9ba00c0d30492ae73e3a230 https://play.rust-lang.org/?version=stable&mode=debug&editio...
- hombre_fatal 6y agoYeah, I never liked how in TOML once you start a [table], you can never go back to the top level, just start more [tables]. What it means in practice is that if you want to use [table] syntax because it's more readable for this one key, you have to move it to the very end, away from the keys it was related to. Wasn't impressed.