Skip to main content

apply_mut

Macro apply_mut 

Source
macro_rules! apply_mut {
    ($current:expr, $patch:expr) => { ... };
}
Expand description

Applies a JSON Merge Patch (RFC 7396) in-place.

Modifies the current value directly.

ยงExample

use serde_patch::apply_mut;

#[derive(serde::Serialize, serde::Deserialize, PartialEq, Debug)]
struct User { id: u32, name: String }

let mut user = User { id: 1, name: "old".to_string() };
let patch = r#"{ "name": "new" }"#;

apply_mut!(&mut user, patch).unwrap();
assert_eq!(user.name, "new");
assert_eq!(user.id, 1);