Skip to main content

Merger

Trait Merger 

Source
pub trait Merger<S>: Send + Sync {
    // Required method
    fn merge(&self, trunk: &mut S, branch: S);

    // Provided method
    fn finish<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _trunk: &'life1 mut S,
    ) -> Pin<Box<dyn Future<Output = Result<(), BspError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

How a branched state rejoins the trunk.

Implementations are consumer-owned: the engine knows nothing about what S fields mean. A typical merger replays a branch’s delta into the trunk (e.g. folding a child store’s integer deltas and rolling up metrics, the way the reference consumer’s parallel tool map-reduce does).

Required Methods§

Source

fn merge(&self, trunk: &mut S, branch: S)

Folds one finished branch state back into the trunk.

Provided Methods§

Source

fn finish<'life0, 'life1, 'async_trait>( &'life0 self, _trunk: &'life1 mut S, ) -> Pin<Box<dyn Future<Output = Result<(), BspError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Finalizes a barrier fold: called exactly once after the last merge of a multi-node superstep barrier (never called for single-node frontiers, which mutate the trunk directly and never fold).

This is the hook for all-at-once merge semantics: merge can accumulate the branch states (interior mutability) and finish collapses them into the trunk in one shot — e.g. the reference consumer’s reducer barriers fold a whole Vec<GraphState> through one async, fallible reduction instead of pairwise folds.

It is async because barrier finalization may itself be a computation (the reference consumer’s reducers call LLMs), and fallible so a failed collapse aborts the run loudly instead of silently continuing with an unreduced trunk. The default is a no-op Ok(()), which is what pairwise merge-only mergers want.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<S, F> Merger<S> for F
where F: Fn(&mut S, S) + Send + Sync,

Any Fn(&mut S, S) closure is a merger.