From 99eb4eab760e96182c96ae992c2beae5778557f3 Mon Sep 17 00:00:00 2001 From: Sven Marnach Date: Fri, 27 Mar 2020 23:43:35 +0100 Subject: [PATCH] Implement Eq for Map, Number and Value. These types already have `PartialEq` implementations which define equivalence relations, so we can implement `Eq` as well. Fixes #638. --- src/map.rs | 2 ++ src/number.rs | 6 +++++- src/value/mod.rs | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/map.rs b/src/map.rs index 98f13b2..2b49ce4 100644 --- a/src/map.rs +++ b/src/map.rs @@ -233,6 +233,8 @@ impl PartialEq for Map { } } +impl Eq for Map {} + /// Access an element of this map. Panics if the given key is not present in the /// map. /// diff --git a/src/number.rs b/src/number.rs index cedd2bb..fd1fac9 100644 --- a/src/number.rs +++ b/src/number.rs @@ -16,7 +16,7 @@ use serde::de::{IntoDeserializer, MapAccess}; pub(crate) const TOKEN: &str = "$serde_json::private::Number"; /// Represents a JSON number, whether integer or floating point. -#[derive(Clone, PartialEq)] +#[derive(Clone, Eq, PartialEq)] pub struct Number { n: N, } @@ -31,6 +31,10 @@ enum N { Float(f64), } +// Implementing Eq is fine since any float values are always finite. +#[cfg(not(feature = "arbitrary_precision"))] +impl Eq for N {} + #[cfg(feature = "arbitrary_precision")] type N = String; diff --git a/src/value/mod.rs b/src/value/mod.rs index 3ddabe2..d806ee9 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -107,7 +107,7 @@ pub use crate::raw::RawValue; /// Represents any valid JSON value. /// /// See the `serde_json::value` module documentation for usage examples. -#[derive(Clone, PartialEq)] +#[derive(Clone, Eq, PartialEq)] pub enum Value { /// Represents a JSON null value. ///