Skip to main content

Fold

Trait Fold 

Source
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§

Source

fn init(&self, context: &FoldContext) -> S

Get the initial state before any entries are processed.

Source

fn reduce(&self, state: S, entry: &L, context: &FoldContext) -> S

Process a single entry and return the new state.

Provided Methods§

Source

fn finalize(&self, state: S, _context: &FoldContext) -> S

Finalize the state after all entries are processed; default returns state unchanged.

Source

fn derive<'a, I>(&self, entries: I, context: &FoldContext) -> FoldOutcome<S>
where Self: Sized, I: IntoIterator<Item = &'a L>, L: 'a,

Derive state from an iterator of entries.

Source

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,

Derive state with a filter.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<L, S, T> Fold<L, S> for Arc<T>
where T: Fold<L, S> + ?Sized,

Source§

fn init(&self, context: &FoldContext) -> S

Source§

fn reduce(&self, state: S, entry: &L, context: &FoldContext) -> S

Source§

fn finalize(&self, state: S, context: &FoldContext) -> S

Source§

impl<L, S, T> Fold<L, S> for Box<T>
where T: Fold<L, S> + ?Sized,

Source§

fn init(&self, context: &FoldContext) -> S

Source§

fn reduce(&self, state: S, entry: &L, context: &FoldContext) -> S

Source§

fn finalize(&self, state: S, context: &FoldContext) -> S

Implementors§

Source§

impl<L1, L2, S, F, M> Fold<L1, S> for MapFold<L1, L2, S, F, M>
where L1: Send + Sync, L2: Send + Sync, S: Send + Sync, F: Fold<L2, S>, M: Fn(&L1) -> L2 + Send + Sync,

Source§

impl<L, S, F, P> Fold<L, S> for FilterFold<L, S, F, P>
where L: Send + Sync, S: Send + Sync, F: Fold<L, S>, P: Fn(&L) -> bool + Send + Sync,

Source§

impl<L, S, I, St, F> Fold<L, S> for FnFold<L, S, I, St, F>
where L: Send + Sync, S: Send + Sync, I: Fn(&FoldContext) -> S + Send + Sync, St: Fn(S, &L, &FoldContext) -> S + Send + Sync, F: Fn(S, &FoldContext) -> S + Send + Sync,

Source§

impl<L> Fold<L, CommonFoldState> for CommonFold<L>

Source§

impl<L> Fold<L, bool> for AnyFold<L>

Source§

impl<L> Fold<L, i64> for SumI64Fold<L>

Source§

impl<L> Fold<L, usize> for CountFold<L>

Source§

impl<L> Fold<L, usize> for FilterCountFold<L>