Skip to main content

apply

Function apply 

Source
pub fn apply(root: &mut Value, op: &PatchOp)
Expand description

Applies a single PatchOp to root (in place).

  • set deep merge: descends along the path creating objects as needed, then RFC 7396 merges at the leaf;
  • replace: same descent, but the leaf value is replaced wholesale (no deep merge) — for enums / tagged unions that swap as a whole;
  • del: descends along the path and removes the final key.

Path descent auto-creates missing intermediate objects and promotes non-object nodes to empty objects along the way. An empty-path set merge-patches the root itself; an empty-path replace swaps the root; an empty-path del resets the root to an empty object (not null, so later descents keep working).

A malformed op (set/replace without a value) is logged and skipped: the root is left untouched, and the skip is made visible rather than silent so client drift against the server is observable.