Batch

Struct Batch 

Source
pub struct Batch<A: Adapter> { /* private fields */ }
Expand description

A batch collector for aggregating and optimizing multiple mutations.

Batch is used internally to collect multiple mutations and optimize them before creating the final mutation. It can merge consecutive append operations and eliminate redundant mutations.

§Type Parameters

  • A - The adapter type used for serialization

§Example

use morphix::{Batch, JsonAdapter, Mutation, MutationKind};
use serde_json::json;

let mut batch = Batch::<JsonAdapter>::new();

// Load multiple mutations
batch.load(Mutation {
    path_rev: vec!["field".into()],
    operation: MutationKind::Replace(json!(1)),
}).unwrap();

// Dump optimized mutations
let optimized = batch.dump();

Implementations§

Source§

impl<A: Adapter> Batch<A>

Source

pub fn new() -> Self

Creates a new empty batch.

Source

pub fn load(&mut self, mutation: Mutation<A>) -> Result<(), MutationError>

Loads a Mutation into the batch, potentially merging with existing mutations.

§Arguments
  • mutation - mutation to add to the batch
§Errors
Source

pub fn dump(&mut self) -> Option<Mutation<A>>

Dumps all accumulated mutations as a single optimized mutation.

  • Returns None if no mutations have been accumulated.
  • Returns a single mutation if only one mutation exists.
  • Returns a Batch mutation if multiple mutations exist.

Trait Implementations§

Source§

impl<A: Adapter> Debug for Batch<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> Default for Batch<A>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<A> UnwindSafe for Batch<A>

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> 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, 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.