Skip to content

Commit

Permalink
Merge pull request #640 from smarnach/smarnach/eq-impls
Browse files Browse the repository at this point in the history
Implement Eq for Map, Number and Value.
  • Loading branch information
dtolnay authored Mar 28, 2020
2 parents 50656bd + 99eb4ea commit 4ac9f6c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
6 changes: 5 additions & 1 deletion src/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down

0 comments on commit 4ac9f6c

Please sign in to comment.