Skip to content

Commit

Permalink
impl Hash for Value when "preserve_order" feature is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardycl committed Apr 25, 2024
1 parent a3f62bb commit d337517
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/map.rs
Expand Up @@ -368,6 +368,14 @@ impl PartialEq for Map<String, Value> {

impl Eq for Map<String, Value> {}

#[cfg(not(feature = "preserve_order"))]
impl Hash for Map<String, Value> {
#[inline]
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.map.hash(state)
}
}

/// Access an element of this map. Panics if the given key is not present in the
/// map.
///
Expand Down
1 change: 1 addition & 0 deletions src/value/mod.rs
Expand Up @@ -113,6 +113,7 @@ pub use crate::raw::{to_raw_value, RawValue};
///
/// See the [`serde_json::value` module documentation](self) for usage examples.
#[derive(Clone, Eq, PartialEq)]
#[cfg_attr(not(feature = "preserve_order"), derive(Hash))]
pub enum Value {
/// Represents a JSON null value.
///
Expand Down

0 comments on commit d337517

Please sign in to comment.