pub fn diff(left: &Value, right: &Value) -> PatchExpand description
Diff two Platform Value documents and generate a Platform Value Patch (RFC 6902).
ยงExample
Diff two JSONs:
#[macro_use]
use platform_value::{from_value, patch, platform_value};
use platform_value::patch::diff;
let left = platform_value!({
"title": "Goodbye!",
"author" : {
"givenName" : "John",
"familyName" : "Doe"
},
"tags":[ "example", "sample" ],
"content": "This will be unchanged"
});
let right = platform_value!({
"title": "Hello!",
"author" : {
"givenName" : "John"
},
"tags": [ "example" ],
"content": "This will be unchanged",
"phoneNumber": "+01-123-456-7890"
});
let p = diff(&left, &right);
assert_eq!(p, from_value(platform_value!([
{ "op": "remove", "path": "/author/familyName" },
{ "op": "remove", "path": "/tags/1" },
{ "op": "replace", "path": "/title", "value": "Hello!" },
{ "op": "add", "path": "/phoneNumber", "value": "+01-123-456-7890" },
])).unwrap());
let mut doc = left.clone();
patch(&mut doc, &p).unwrap();
assert_eq!(doc, right);