macro_rules! apply {
($current:expr, $patch_json:expr) => { ... };
}Expand description
Applies a JSON Merge Patch (RFC 7396).
Consumes the current value and returns the updated value.
ยงExample
use serde_patch::apply;
#[derive(serde::Serialize, serde::Deserialize, PartialEq, Debug)]
struct User { id: u32, name: String }
let current = User { id: 1, name: "old".to_string() };
let patch = r#"{ "name": "new" }"#;
let updated = apply!(current, patch).unwrap();
assert_eq!(updated.name, "new");
assert_eq!(updated.id, 1);