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

impl Hash for Value when "preserve_order" feature is not set #1127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

edwardycl
Copy link

IndexMap is the only type that is used within Value that does not implement Hash, and it is by design: indexmap-rs/indexmap#288 (comment)

If "preserve_order" feature is not set, Value::Object uses BTreeMap instead of IndexMap so it is possible to auto-impl Hash for Value.

Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cargo features are required to be additive, so enabling a feature cannot result in an impl being removed.

@edwardycl
Copy link
Author

edwardycl commented Apr 25, 2024

Now that I think about it, since the type of key is fixed to String, IndexMap can also be hashed by sorting its key-value in a consistent order. It doesn't break the Eq-Hash relationship, and we can implement Hash regardless of the "preserve_order" feature. What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants