Skip to main content

ChainState

Trait ChainState 

Source
pub trait ChainState: Builder {
    type State: Default;

    // Required methods
    fn wants_bodies() -> bool;
    fn observe(state: &mut Self::State, input: &Self::Input);
    fn observe_records(state: &mut Self::State, records: usize);
    fn from_state(state: Self::State) -> Self;
}
Expand description

A builder whose batches carry state derived from a whole chain, computed before the chain’s first push.

Builder::seal receives the chain at once, which a chain of pool-backed chunks cannot supply without holding every body resident at the same time. An implementor splits the derivation instead: a caller folds the chain into State one entry at a time, then builds from it.

A caller folds each chain entry exactly once, through observe when it holds the entry’s contents and through observe_records when it does not, so an implementor may accumulate the same figure in both without double counting. Which one an entry takes is the caller’s choice, so an implementor reads no meaning into it beyond what each carries.

Required Associated Types§

Source

type State: Default

State accumulated across a chain.

Required Methods§

Source

fn wants_bodies() -> bool

Whether the state is worth reading a chain entry’s contents for when they are not already at hand. A caller that holds them passes them on regardless.

Source

fn observe(state: &mut Self::State, input: &Self::Input)

Fold one chain entry’s contents into state.

Source

fn observe_records(state: &mut Self::State, records: usize)

Fold one chain entry’s update count into state, for a caller that reads no bodies.

Source

fn from_state(state: Self::State) -> Self

Build with state installed.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§