Op

Enum Op 

Source
pub enum Op {
    Set {
        path: Path,
        value: Value,
    },
    Delete {
        path: Path,
    },
    Append {
        path: Path,
        value: Value,
    },
    MergeObject {
        path: Path,
        value: Value,
    },
    Increment {
        path: Path,
        amount: Number,
    },
    Decrement {
        path: Path,
        amount: Number,
    },
    Insert {
        path: Path,
        index: usize,
        value: Value,
    },
    Remove {
        path: Path,
        value: Value,
    },
    LatticeMerge {
        path: Path,
        value: Value,
    },
}
Expand description

A single patch operation.

Operations are the atomic units of change. Each operation targets a specific path in the document and performs a specific mutation.

Variants§

§

Set

Set a value at the path.

Creates intermediate objects if they don’t exist. Returns error if array index is out of bounds.

Fields

§path: Path

Target path.

§value: Value

Value to set.

§

Delete

Delete the value at the path.

No-op if the path doesn’t exist.

Fields

§path: Path

Target path.

§

Append

Append a value to an array at the path.

Creates the array if it doesn’t exist. Returns error if the target exists but is not an array.

Fields

§path: Path

Target path (must be an array or non-existent).

§value: Value

Value to append.

§

MergeObject

Merge an object into the object at the path.

Creates the object if it doesn’t exist. Returns error if the target exists but is not an object.

Fields

§path: Path

Target path (must be an object or non-existent).

§value: Value

Object to merge.

§

Increment

Increment a numeric value at the path.

Returns error if the target is not a number.

Fields

§path: Path

Target path (must be a number).

§amount: Number

Amount to increment by.

§

Decrement

Decrement a numeric value at the path.

Returns error if the target is not a number.

Fields

§path: Path

Target path (must be a number).

§amount: Number

Amount to decrement by.

§

Insert

Insert a value at a specific index in an array.

Shifts elements to the right. Returns error if index is out of bounds or target is not an array.

Fields

§path: Path

Target path (must be an array).

§index: usize

Index to insert at.

§value: Value

Value to insert.

§

Remove

Remove the first occurrence of a value from an array.

No-op if the value is not found. Returns error if the target is not an array.

Fields

§path: Path

Target path (must be an array).

§value: Value

Value to remove.

§

LatticeMerge

Merge a lattice delta into an existing value at path.

When applied via LatticeRegistry, performs a proper lattice merge. Without a registry, falls back to Op::Set semantics (writes the delta directly).

Fields

§path: Path

Target path.

§value: Value

Delta value to merge.

Implementations§

Source§

impl Op

Source

pub fn set(path: Path, value: impl Into<Value>) -> Self

Create a Set operation.

Source

pub fn delete(path: Path) -> Self

Create a Delete operation.

Source

pub fn append(path: Path, value: impl Into<Value>) -> Self

Create an Append operation.

Source

pub fn merge_object(path: Path, value: impl Into<Value>) -> Self

Create a MergeObject operation.

Source

pub fn increment(path: Path, amount: impl Into<Number>) -> Self

Create an Increment operation.

Source

pub fn decrement(path: Path, amount: impl Into<Number>) -> Self

Create a Decrement operation.

Source

pub fn insert(path: Path, index: usize, value: impl Into<Value>) -> Self

Create an Insert operation.

Source

pub fn remove(path: Path, value: impl Into<Value>) -> Self

Create a Remove operation.

Source

pub fn lattice_merge(path: Path, value: impl Into<Value>) -> Self

Create a LatticeMerge operation.

Source

pub fn path(&self) -> &Path

Get the path this operation targets.

Source

pub fn path_mut(&mut self) -> &mut Path

Get a mutable reference to the path.

Source

pub fn name(&self) -> &'static str

Get the operation name.

Trait Implementations§

Source§

impl Clone for Op

Source§

fn clone(&self) -> Op

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Op

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Op

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Extend<Op> for Patch

Source§

fn extend<I: IntoIterator<Item = Op>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl FromIterator<Op> for Patch

Source§

fn from_iter<I: IntoIterator<Item = Op>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl PartialEq for Op

Source§

fn eq(&self, other: &Op) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Op

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Op

Auto Trait Implementations§

§

impl Freeze for Op

§

impl RefUnwindSafe for Op

§

impl Send for Op

§

impl Sync for Op

§

impl Unpin for Op

§

impl UnwindSafe for Op

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,