-
Notifications
You must be signed in to change notification settings - Fork 571
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
Implement Eq for Value, Number and Map #638
Comments
Could you share a bit about your use case that requires these impls? |
The specific use case where this came up was JSON schema validation. The I personally see this more as a matter of consistency rather than specific to a use case, though. If a |
Thanks, makes sense. I would accept a PR for Eq impls. |
These types already have `PartialEq` implementations which define equivalence relations, so we can implement `Eq` as well. Fixes serde-rs#638.
These types already have `PartialEq` implementations which define equivalence relations, so we can implement `Eq` as well. Fixes serde-rs#638.
All these types currently implement
PartialEq
. However, they also fulfil the requirements forEq
, so we may implement that trait as well.The
Map
type currently has a custom implementation forPartialEq
, which looks identical to what we would get by simply derivingPartialEq
. If thepreserve_order
feature is enabled, the code is identical to thePartialEq
implementation forIndexMap
. For the case thatpreserve_order
is disabled, the code simply defers to the implementation forBTreeMap
. BothIndexMap
andBTreeMap
implementEq
.The
Number
type has three variants, wrappingu64
,i64
andf64
respectively. The former two areEq
, while the latter is onlyPartialEq
. However, since floating-point numbers in JSON are always finite, we can assume them to beEq
as well, so we can implementEq
forNumber
.Once
Map
andNumber
implementEq
, it can be derived forValue
.The text was updated successfully, but these errors were encountered: