patch

Function patch 

Source
pub fn patch(
    doc: &mut Value,
    patch: &[PatchOperation],
) -> Result<(), PatchError>
Expand description

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.

ยงExample

Create and patch document:

#[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" }
]));