pub struct PatchBuilder { /* private fields */ }Expand description
A builder for constructing JSON Patches programmatically.
This provides a more ergonomic way to create patches when you know exactly what operations you want to perform.
§Example
use ag_ui_core::patch::PatchBuilder;
use serde_json::json;
let patch = PatchBuilder::new()
.add("/name", json!("Alice"))
.replace("/age", json!(31))
.remove("/temp")
.build();
assert_eq!(patch.0.len(), 3);Implementations§
Source§impl PatchBuilder
impl PatchBuilder
Sourcepub fn add(self, path: impl AsRef<str>, value: JsonValue) -> Self
pub fn add(self, path: impl AsRef<str>, value: JsonValue) -> Self
Adds an “add” operation to the patch.
The add operation adds a value at the target location. If the target location specifies an array index, the value is inserted at that index.
Sourcepub fn remove(self, path: impl AsRef<str>) -> Self
pub fn remove(self, path: impl AsRef<str>) -> Self
Adds a “remove” operation to the patch.
The remove operation removes the value at the target location.
Sourcepub fn replace(self, path: impl AsRef<str>, value: JsonValue) -> Self
pub fn replace(self, path: impl AsRef<str>, value: JsonValue) -> Self
Adds a “replace” operation to the patch.
The replace operation replaces the value at the target location with the new value.
Sourcepub fn move_value(self, from: impl AsRef<str>, path: impl AsRef<str>) -> Self
pub fn move_value(self, from: impl AsRef<str>, path: impl AsRef<str>) -> Self
Adds a “move” operation to the patch.
The move operation removes the value at a specified location and adds it to the target location.
Sourcepub fn copy(self, from: impl AsRef<str>, path: impl AsRef<str>) -> Self
pub fn copy(self, from: impl AsRef<str>, path: impl AsRef<str>) -> Self
Adds a “copy” operation to the patch.
The copy operation copies the value at a specified location to the target location.
Trait Implementations§
Source§impl Clone for PatchBuilder
impl Clone for PatchBuilder
Source§fn clone(&self) -> PatchBuilder
fn clone(&self) -> PatchBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more