Skip to main content

StateMerge

Trait StateMerge 

Source
pub trait StateMerge: Sized {
    type Contribution: Default + Send + Sync + 'static;

    // Required methods
    fn merge(self, update: Self) -> Self;
    fn merge_contribution(self, contribution: Self::Contribution) -> Self;
}
Expand description

State-level merge: how an incoming update folds into the current state. The dispatch-loop counterpart to Reducer<T>, one level up — implemented on the whole S shape rather than a single slot.

Two merge axes:

  • Self::merge folds two same-shape S values (used by parallel-branch joins via add_send_edges, where two branches each produce a complete S and the dispatcher needs to combine them).
  • Self::merge_contribution folds an Option-wrapped contribution from one node into the current state. The Contribution type — declared via the type Contribution associated item — names which slots the node actually wrote, distinguishing “no contribution” from “contributed the default value”. This is the canonical StateGraph::add_contributing_node entry point — closer to LangGraph’s TypedDict partial-return shape than the same-shape merge alone could express.

The companion entelix-graph-derive::StateMerge derive macro generates both methods plus the <Name>Contribution companion struct. Manual impls are supported when field-by-field shape doesn’t fit (e.g. cross-field invariants enforced at merge time).

Required Associated Types§

Source

type Contribution: Default + Send + Sync + 'static

Companion type carrying an Option-wrapped slot per field of Self. The derive macro generates this struct automatically; manual implementors define their own.

Required Methods§

Source

fn merge(self, update: Self) -> Self

Fold update into self and return the merged state. Implementations must be deterministic for the same reason Reducer::reduce is — the merge runs inside the dispatch loop and a non-deterministic implementation breaks crash-resume reproducibility.

Source

fn merge_contribution(self, contribution: Self::Contribution) -> Self

Fold a Self::Contribution (an Option-wrapped partial state) into self. Slots the node didn’t write (None) leave the current value untouched; slots it did (Some) merge through the per-field reducer for Annotated<T, R> fields, or replace for plain fields.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§