Module patch

Module patch 

Source
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
CopyOperation
Platform Value Patch ‘copy’ operation representation
MoveOperation
Platform Value Patch ‘move’ operation representation
Patch
Representation of Platform Value Patch (list of patch operations)
PatchError
This type represents all possible errors that can occur when applying Platform Value patch
RemoveOperation
Platform Value Patch ‘remove’ operation representation
ReplaceOperation
Platform Value Patch ‘replace’ operation representation
TestOperation
Platform Value Patch ‘test’ operation representation

Enums§

PatchErrorKind
This type represents all possible errors that can occur when applying Platform Value patch
PatchOperation
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.