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::mergefolds two same-shapeSvalues (used by parallel-branch joins viaadd_send_edges, where two branches each produce a completeSand the dispatcher needs to combine them).Self::merge_contributionfolds anOption-wrapped contribution from one node into the current state. TheContributiontype — declared via thetype Contributionassociated item — names which slots the node actually wrote, distinguishing “no contribution” from “contributed the default value”. This is the canonicalStateGraph::add_contributing_nodeentry 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§
Sourcetype Contribution: Default + Send + Sync + 'static
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§
Sourcefn merge(self, update: Self) -> Self
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.
Sourcefn merge_contribution(self, contribution: Self::Contribution) -> Self
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.