Skip to content

Commit d337517

Browse files
committed
impl Hash for Value when "preserve_order" feature is not set
1 parent a3f62bb commit d337517

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/map.rs

+8
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,14 @@ impl PartialEq for Map<String, Value> {
368368

369369
impl Eq for Map<String, Value> {}
370370

371+
#[cfg(not(feature = "preserve_order"))]
372+
impl Hash for Map<String, Value> {
373+
#[inline]
374+
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
375+
self.map.hash(state)
376+
}
377+
}
378+
371379
/// Access an element of this map. Panics if the given key is not present in the
372380
/// map.
373381
///

src/value/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ pub use crate::raw::{to_raw_value, RawValue};
113113
///
114114
/// See the [`serde_json::value` module documentation](self) for usage examples.
115115
#[derive(Clone, Eq, PartialEq)]
116+
#[cfg_attr(not(feature = "preserve_order"), derive(Hash))]
116117
pub enum Value {
117118
/// Represents a JSON null value.
118119
///

0 commit comments

Comments
 (0)