pub trait Fold<L, S> {
// Required methods
fn initial(&self, context: &FoldContext) -> S;
fn step(&self, state: S, entry: &L, context: &FoldContext) -> S;
// Provided methods
fn finalize(&self, state: S, _context: &FoldContext) -> S { ... }
fn derive<'a, I>(&self, entries: I, context: &FoldContext) -> FoldOutcome<S>
where Self: Sized,
I: IntoIterator<Item = &'a L>,
L: 'a { ... }
fn derive_filtered<'a, I, F>(
&self,
entries: I,
context: &FoldContext,
filter: F,
) -> FoldOutcome<S>
where Self: Sized,
I: IntoIterator<Item = &'a L>,
L: 'a,
F: Fn(&L) -> bool { ... }
}Expand description
Core fold trait for deriving state from entries.
A fold is the “measurement operator” that collapses a sequence of entries into a derived state. The fold is parameterized by:
- L: The entry type (LogEntry, AtomEntry, MemoryEntry, etc.)
- S: The derived state type
Folds are deterministic: same entries + same context = same state.
Required Methods§
Sourcefn initial(&self, context: &FoldContext) -> S
fn initial(&self, context: &FoldContext) -> S
Get the initial state before any entries are processed.
Sourcefn step(&self, state: S, entry: &L, context: &FoldContext) -> S
fn step(&self, state: S, entry: &L, context: &FoldContext) -> S
Process a single entry and return the new state.
This is the core step function: state’ = step(state, entry, context)
Provided Methods§
Sourcefn finalize(&self, state: S, _context: &FoldContext) -> S
fn finalize(&self, state: S, _context: &FoldContext) -> S
Finalize the state after all entries are processed.
Default implementation returns state unchanged.
Sourcefn derive<'a, I>(&self, entries: I, context: &FoldContext) -> FoldOutcome<S>
fn derive<'a, I>(&self, entries: I, context: &FoldContext) -> FoldOutcome<S>
Derive state from an iterator of entries.
This is the main entry point for using a fold.
Sourcefn derive_filtered<'a, I, F>(
&self,
entries: I,
context: &FoldContext,
filter: F,
) -> FoldOutcome<S>
fn derive_filtered<'a, I, F>( &self, entries: I, context: &FoldContext, filter: F, ) -> FoldOutcome<S>
Derive state with a filter.