diff --git a/patch-db/Cargo.toml b/patch-db/Cargo.toml index d7148ae..304897f 100644 --- a/patch-db/Cargo.toml +++ b/patch-db/Cargo.toml @@ -16,7 +16,7 @@ version = "0.1.0" async-trait = "0.1.42" fd-lock-rs = "0.1.3" futures = "0.3.8" -indexmap = "1.6.2" +indexmap = { version = "1.6.2", features = ["serde"] } json-patch = { path = "../json-patch" } json-ptr = { path = "../json-ptr" } lazy_static = "1.4.0" diff --git a/patch-db/src/model.rs b/patch-db/src/model.rs index 202ce3b..b0a97a9 100644 --- a/patch-db/src/model.rs +++ b/patch-db/src/model.rs @@ -3,7 +3,7 @@ use std::hash::Hash; use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; -use indexmap::IndexSet; +use indexmap::{IndexMap, IndexSet}; use json_ptr::JsonPointer; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -385,6 +385,13 @@ impl + Ord, V> Map for BTreeMap { self.get(key) } } +impl + Eq + Hash, V> Map for IndexMap { + type Key = K; + type Value = V; + fn get(&self, key: &Self::Key) -> Option<&Self::Value> { + IndexMap::get(self, key) + } +} #[derive(Debug)] pub struct MapModel(Model) @@ -493,3 +500,10 @@ where { type Model = MapModel>; } +impl HasModel for IndexMap +where + K: Serialize + for<'de> Deserialize<'de> + Hash + Eq + AsRef, + V: Serialize + for<'de> Deserialize<'de>, +{ + type Model = MapModel>; +}