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

Keep ordering of deserialized maps #216

Closed
dlo9 opened this issue Jul 26, 2021 · 3 comments · Fixed by #217
Closed

Keep ordering of deserialized maps #216

dlo9 opened this issue Jul 26, 2021 · 3 comments · Fixed by #217

Comments

@dlo9
Copy link

dlo9 commented Jul 26, 2021

Serde's yaml deserialization supports maintaining the order of map types (at least in yaml/json, haven't looked at other formats) by using LinkedHashMap instead of HashMap. Quickly perusing through config-rs, it looks like the table value uses HashMap and so will always lose the ordering of a map.

AFAICT, a fix to this would be as simple as changing HashMap to LinkedHashMap in the appropriate places, but since that type is exposed to the API, it could be considered a breaking change. Would the project be receptive to such a change?

@matthiasbeyer
Copy link
Member

Hi,

thanks, that's a nice idea to pursue. Maybe we can work together and explore whether it would be possible to make the YAML de/serialization mechanisms generic over HashMap vs LinkedHashMap? I don't know whether such a thing is possible, but maybe it is...
If not, maybe adding a new "backend type" which explicitely uses LinkedHashMap is possible?

If all fails, we can always release breaking changes as long as we're in version 0.x.y, although I would prefer to not have to do this.

Long story short: Consider me interested! 😆

@dlo9
Copy link
Author

dlo9 commented Jul 27, 2021

Great! I'll see if can can find some time in the next few days to make a test case and initial breaking implementation, and then we can go from there

@dlo9 dlo9 mentioned this issue Jul 29, 2021
3 tasks
@dlo9
Copy link
Author

dlo9 commented Jul 29, 2021

Just made a draft PR for an initial implementation -- there's a few things I discovered while making the change which I'd like to fix, but it will probably take me a few days to get around to. In the meantime, let me know if you have any changes or requested comments and I'll make it ready when I'm happy with the PR

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 a pull request may close this issue.

2 participants