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.
This commit is contained in:
Sven Marnach 2020-03-27 23:43:35 +01:00
parent 9c3b182b97
commit 99eb4eab76
No known key found for this signature in database
GPG Key ID: BD1A191F301D644E
3 changed files with 8 additions and 2 deletions

View File

@ -233,6 +233,8 @@ impl PartialEq for Map<String, Value> {
}
}
impl Eq for Map<String, Value> {}
/// Access an element of this map. Panics if the given key is not present in the
/// map.
///

View File

@ -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;

View File

@ -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.
///