pub fn apply_jmap_patch(
target: &mut Map<String, Value>,
path: &str,
value: Value,
) -> Result<(), PatchPathError>Expand description
Apply one RFC 8620 §5.3 PatchObject entry (path → value) to
target in-place.
path is a PatchObject key: an RFC 6901 JSON Pointer with the
implicit leading / omitted (e.g. "mailboxIds/abc123"). Each
/-separated reference token is decoded per RFC 6901 §4 (~1 → /,
then ~0 → ~). Every token before the last must name an existing
object member; the last token names the member to set. A null
value removes that member (a no-op when it is absent); any other
value inserts or replaces it.
Extracted from per-crate copies in bd:JMAP-j6ab. Extension servers MUST call this rather than reimplement it.
Empty tokens are legal: RFC 6901 §3 allows a zero-length
reference-token, and its §5 example evaluates "/" to the member
named "". The RFC 8620 §5.3 “null sets the property default” rule
is type-specific and left to the caller. The rule that no two pointers
in one PatchObject may be prefixes of each other is checked by
apply_patch_object.
§Errors
Returns PatchPathError when a part before the last does not exist
(ParentMissing), is an array
(InsideArray) or is another
non-object value (ParentNotObject)
or is a Binary value below a metadata/<namespace> or
privateMetadata/<namespace> prefix
(InsideBinary; an object with
"@type": "Binary", draft-ietf-jmap-metadata-05 §2.1.1),
when path contains an invalid escape
(InvalidEscape), or when the
number of /-separated segments in path plus the object/array
nesting of value (a scalar nests 0 levels) exceeds the crate’s
MAX_MERGE_PATCH_DEPTH DoS-guard cap
(DepthExceeded).
§Mutation contract
A single call is all-or-nothing: on Err, target is unchanged.
A PatchObject has several entries, and an error on a later entry
does not undo earlier ones, so callers applying a whole PatchObject
MUST use apply_patch_object.