maciejhirsz / json-rust

JSON implementation in Rust
Apache License 2.0
566 stars 63 forks source link

`Hash` implementation #177

Open timothee-haudebourg opened 4 years ago

timothee-haudebourg commented 4 years ago

I need to organize JsonValues into a HashSet however I just noticed that JsonValue does not implement the Hash trait. Is there a reason for that?

timothee-haudebourg commented 4 years ago

Going deeper, I see that Object is implemented as a Binary tree, so there is a defined order between the keys of an object. Then I see no reason why it would not be possible to define an order between every JSON value? And a Hash?

maciejhirsz commented 4 years ago

The keys are sorted into a tree, but the tree will be balanced differently depending on insertion order, so hashes would differ. If you are fine with matching objects with keys at insertion order then adding Hash impl should be pretty straight forward (at least in the new implementation, which is much cleaner, though still quite a bit in flux).

timothee-haudebourg commented 3 years ago

When can we expect this new implementation to be released? Can we follow its development somewhere?

A248 commented 2 years ago

Even if Object does not have a defined order, it is still possible to create a Hash implementation for it.

See https://github.com/rust-lang/rust/pull/48366 for an implementation of Hash on an unordered data structure.