Skip to main content

DiffJson

Trait DiffJson 

Source
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§

Source

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".

Implementations on Foreign Types§

Source§

impl DiffJson for BTreeMap<String, JsonScalar>

Source§

fn diff_with(&self, other: &Self) -> BTreeMap<String, (JsonScalar, JsonScalar)>

Source§

impl DiffJson for Value

Source§

fn diff_with(&self, other: &Self) -> BTreeMap<String, (JsonScalar, JsonScalar)>

Implementors§