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

Preserve order of items in maps #234

Merged
merged 4 commits into from
Feb 27, 2023
Merged

Preserve order of items in maps #234

merged 4 commits into from
Feb 27, 2023

Conversation

jcaesar
Copy link
Contributor

@jcaesar jcaesar commented Dec 27, 2022

Minus one TODO. My first impulse was to reach for indexmap, but Value::Map is never actually accessed by key.

The TOML format has a restriction that if a table itself contains
tables, all keys with non-table values must be emitted first.
This commit enforces said order by modifying value::Values recursively
before handing them to the TOML serializer.
@jcaesar
Copy link
Contributor Author

jcaesar commented Jan 5, 2023

I noticed that once map order no longer depends on the key, the TOML problem #194 is easily solvable by reordering (and without affecting other formats like #221 does). I've added that to this PR.
[Edit:] Using toml 0.6 fixes this issue more cleanly.

toml 0.6 is based on toml_edit, it:
 - allows to preserve order
 - fixes some mis-serializaitons, e.g. with mixed lists
 - does not require order of non-/table values in maps

This reverts the previous commit.
@dflemstr dflemstr merged commit fca64c6 into dflemstr:master Feb 27, 2023
@jcaesar jcaesar deleted the maporder branch February 28, 2023 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants