pub trait Fold<L, S>: Send + Sync {
// Required methods
fn init(&self, context: &FoldContext) -> S;
fn reduce(&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: collapses a sequence of entries into deterministic derived state.
Required Methods§
Sourcefn init(&self, context: &FoldContext) -> S
fn init(&self, context: &FoldContext) -> S
Get the initial state before any entries are processed.
Sourcefn reduce(&self, state: S, entry: &L, context: &FoldContext) -> S
fn reduce(&self, state: S, entry: &L, context: &FoldContext) -> S
Process a single entry and return the new state.
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 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.
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.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".