BatchTree

Struct BatchTree 

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

A batch collector for aggregating and optimizing multiple mutations.

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

§Example

use morphix::adapter::Json;
use morphix::{BatchTree, Mutation, MutationKind};
use serde_json::json;

let mut batch = BatchTree::<Json>::new();

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

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

Implementations§

Source§

impl<A: Adapter> BatchTree<A>

Source

pub fn new() -> Self

Creates a new empty batch.

Source

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

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

Source

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

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> Default for BatchTree<A>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<A> UnwindSafe for BatchTree<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> 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> 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.