mirror of
https://github.com/serde-rs/json.git
synced 2026-02-18 22:19:08 +00:00
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:
parent
9c3b182b97
commit
99eb4eab76
@ -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.
|
||||
///
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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.
|
||||
///
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user