pub trait DiffJson {
// Required method
fn diff_with(
&self,
other: &Self,
) -> BTreeMap<String, (JsonScalar, JsonScalar)>;
}Expand description
Compares JSON values, or maps of paths, by leaf value.
This is the Rust form of DiffWith. The pair is (self, other).
JsonScalar::Undefined fills the side where a path is absent.
Required Methods§
Sourcefn diff_with(&self, other: &Self) -> BTreeMap<String, (JsonScalar, JsonScalar)>
fn diff_with(&self, other: &Self) -> BTreeMap<String, (JsonScalar, JsonScalar)>
Paths whose leaf values differ.
Paths that are equal on both sides are omitted. JSON null equals
JSON null.
§Examples
use json_traits::{DiffJson, JsonScalar};
use serde_json::json;
let left = json!({ "name": "Stewie", "number": 12 });
let right = json!({ "name": "Stewie", "number": 13, "isAwesome": true });
let diff = left.diff_with(&right);
assert_eq!(
diff.get("number"),
Some(&(JsonScalar::from_integer(12), JsonScalar::from_integer(13)))
);
assert_eq!(
diff.get("isAwesome"),
Some(&(JsonScalar::Undefined, JsonScalar::from(true)))
);
assert!(!diff.contains_key("name"));Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".