MutationKind

Enum MutationKind 

Source
pub enum MutationKind<A: Adapter> {
    Replace(A::Value),
    Append(A::Value),
    Batch(Vec<Mutation<A>>),
}
Expand description

The kind of mutation that occurred.

MutationKind represents the specific type of change made to a value. Different kinds enable optimizations and more precise change descriptions.

§Variants

  • Replace: Complete replacement of a value
  • Append: Append operation for strings and vectors
  • Batch: Multiple mutations combined

§Example

use morphix::{JsonAdapter, Mutation, MutationKind, Observe, observe};
use serde::Serialize;
use serde_json::json;

#[derive(Serialize, Observe)]
struct Document {
    title: String,
    content: String,
    tags: Vec<String>,
}

let mut doc = Document {
    title: "Draft".to_string(),
    content: "Hello".to_string(),
    tags: vec!["todo".to_string()],
};

let mutation = observe!(JsonAdapter, |mut doc| {
    doc.title = "Final".to_string();      // Replace
    doc.content.push_str(" World");       // Append
    doc.tags.push("done".to_string());    // Append
}).unwrap().unwrap();

// The mutation contains a Batch with three kinds
assert!(matches!(mutation.kind, MutationKind::Batch(_)));

Variants§

§

Replace(A::Value)

Replace is the default mutation for DerefMut operations.

§Examples
foo.a.b = 1;        // Replace at .a.b
foo.num *= 2;       // Replace at .num
foo.vec.clear();    // Replace at .vec
§Note

If an operation can be represented as Append, it will be preferred over Replace for efficiency.

§

Append(A::Value)

Append represents adding data to the end of a string or vector. This is more efficient than Replace because only the appended portion needs to be serialized and transmitted.

§Examples
foo.a.b += "text";          // Append to .a.b
foo.a.b.push_str("text");   // Append to .a.b
foo.vec.push(1);            // Append to .vec
foo.vec.extend(iter);       // Append to .vec
§

Batch(Vec<Mutation<A>>)

Batch combines multiple mutations that occurred during a single observation period. This is automatically created when multiple independent changes are detected.

§Optimization

The batch collector (BatchTree) automatically optimizes mutations:

  • Consecutive appends are merged
  • Redundant changes are eliminated
  • Nested paths are consolidated when possible

Trait Implementations§

Source§

impl<A: Adapter> Clone for MutationKind<A>
where A::Value: Clone,

Source§

fn clone(&self) -> Self

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<A: Adapter> Debug for MutationKind<A>
where A::Value: Debug,

Source§

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

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

impl<A: Adapter> PartialEq for MutationKind<A>
where A::Value: PartialEq,

Source§

fn eq(&self, other: &Self) -> 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<A: Adapter> Eq for MutationKind<A>
where A::Value: Eq,

Auto Trait Implementations§

§

impl<A> Freeze for MutationKind<A>
where <A as Adapter>::Value: Freeze,

§

impl<A> RefUnwindSafe for MutationKind<A>
where <A as Adapter>::Value: RefUnwindSafe,

§

impl<A> Send for MutationKind<A>
where <A as Adapter>::Value: Send,

§

impl<A> Sync for MutationKind<A>
where <A as Adapter>::Value: Sync,

§

impl<A> Unpin for MutationKind<A>
where <A as Adapter>::Value: Unpin,

§

impl<A> UnwindSafe for MutationKind<A>
where <A as Adapter>::Value: UnwindSafe,

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> AsDeref<Zero> for T
where T: ?Sized,

Source§

type Target = T

The target type after N dereferences.
Source§

fn as_deref(&self) -> &T

Dereferences self N times.
Source§

impl<T> AsDerefCoinductive<Zero> for T
where T: ?Sized,

Source§

type Target = T

The target type after N dereferences.
Source§

fn as_deref_coinductive(&self) -> &T

Dereferences self N times.
Source§

impl<T> AsDerefMut<Zero> for T
where T: ?Sized,

Source§

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

Mutably dereferences self N times.
Source§

impl<T> AsDerefMutCoinductive<Zero> for T
where T: ?Sized,

Source§

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

Mutably dereferences self N times.
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.