#[non_exhaustive]pub struct PatchObject(/* private fields */);Expand description
A JMAP PatchObject (RFC 8620 §5.3) — a String → JSON map describing
the changes to apply to a record during */set update.
See the module documentation for the path-key semantics and null-leaf removal rule.
§Wire format
PatchObject serialises and deserialises as a plain JSON object via
#[serde(transparent)]. There is no discriminant or wrapper key on the
wire — {"name": "New"} and PatchObject::from_map([("name", json!("New"))])
are equivalent.
§Example
use jmap_types::PatchObject;
use serde_json::{json, Map, Value};
let mut m = Map::new();
m.insert("name".to_owned(), json!("Renamed"));
m.insert("keywords/$flagged".to_owned(), Value::Null);
let patch = PatchObject::from_map(m);
// Wire form is byte-identical to the inner map.
let wire = serde_json::to_string(&patch).unwrap();
assert!(wire.contains("\"name\":\"Renamed\""));
assert!(wire.contains("\"keywords/$flagged\":null"));Implementations§
Source§impl PatchObject
impl PatchObject
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct an empty patch.
An empty patch is a valid no-op update value per RFC 8620 §5.3:
the server accepts it and applies no changes to the target record.
Sourcepub fn from_map(map: Map<String, Value>) -> Self
pub fn from_map(map: Map<String, Value>) -> Self
Wrap an existing serde_json::Map as a PatchObject.
No validation is performed — the caller is responsible for the
keys conforming to RFC 8620 §5.3 path syntax (or the server will
reject the patch with invalidPatch).
Sourcepub fn as_map_mut(&mut self) -> &mut Map<String, Value>
pub fn as_map_mut(&mut self) -> &mut Map<String, Value>
Mutably borrow the inner map for in-place edits.
Sourcepub fn into_inner(self) -> Map<String, Value>
pub fn into_inner(self) -> Map<String, Value>
Consume the PatchObject and return the underlying map.
Trait Implementations§
Source§impl Clone for PatchObject
impl Clone for PatchObject
Source§fn clone(&self) -> PatchObject
fn clone(&self) -> PatchObject
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PatchObject
impl Debug for PatchObject
Source§impl Default for PatchObject
impl Default for PatchObject
Source§fn default() -> PatchObject
fn default() -> PatchObject
Source§impl<'de> Deserialize<'de> for PatchObject
impl<'de> Deserialize<'de> for PatchObject
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<PatchObject> for Map<String, Value>
impl From<PatchObject> for Map<String, Value>
Source§fn from(patch: PatchObject) -> Self
fn from(patch: PatchObject) -> Self
Source§impl PartialEq for PatchObject
impl PartialEq for PatchObject
Source§fn eq(&self, other: &PatchObject) -> bool
fn eq(&self, other: &PatchObject) -> bool
self and other values to be equal, and is used by ==.