Expand description
A Platform Value Patch and Platform Value Merge Patch implementation for Rust.
§Examples
Create and patch document using Platform Value Patch:
#[macro_use]
use platform_value::{Patch, patch, from_value, platform_value};
let mut doc = platform_value!([
{ "name": "Andrew" },
{ "name": "Maxim" }
]);
let p: Patch = from_value(platform_value!([
{ "op": "test", "path": "/0/name", "value": "Andrew" },
{ "op": "add", "path": "/0/happy", "value": true }
])).unwrap();
patch(&mut doc, &p).unwrap();
assert_eq!(doc, platform_value!([
{ "name": "Andrew", "happy": true },
{ "name": "Maxim" }
]));
Create and patch document using Platform Value Merge Patch:
#[macro_use]
use platform_value::{patch::merge, platform_value};
let mut doc = platform_value!({
"title": "Goodbye!",
"author" : {
"givenName" : "John",
"familyName" : "Doe"
},
"tags":[ "example", "sample" ],
"content": "This will be unchanged"
});
let patch = platform_value!({
"title": "Hello!",
"phoneNumber": "+01-123-456-7890",
"author": {
"familyName": null
},
"tags": [ "example" ]
});
merge(&mut doc, &patch);
assert_eq!(doc, platform_value!({
"title": "Hello!",
"author" : {
"givenName" : "John"
},
"tags": [ "example" ],
"content": "This will be unchanged",
"phoneNumber": "+01-123-456-7890"
}));Structs§
- AddOperation
- Platform Value Patch ‘add’ operation representation
- Copy
Operation - Platform Value Patch ‘copy’ operation representation
- Move
Operation - Platform Value Patch ‘move’ operation representation
- Patch
- Representation of Platform Value Patch (list of patch operations)
- Patch
Error - This type represents all possible errors that can occur when applying Platform Value patch
- Remove
Operation - Platform Value Patch ‘remove’ operation representation
- Replace
Operation - Platform Value Patch ‘replace’ operation representation
- Test
Operation - Platform Value Patch ‘test’ operation representation
Enums§
- Patch
Error Kind - This type represents all possible errors that can occur when applying Platform Value patch
- Patch
Operation - Platform Value Patch single patch operation
Functions§
- diff
- Diff two Platform Value documents and generate a Platform Value Patch (RFC 6902).
- merge
- Patch provided Platform Value document (given as
platform_value::Value) in place with Platform Value Merge Patch (RFC 7396). - patch
- Patch provided Platform Value document (given as
platform_value::Value) in-place. If any of the patch is failed, all previous operations are reverted. In case of internal error resulting in panic, document might be left in inconsistent state.