pub enum CommonFold<L> {
Count(CountFold<L>),
FilterCount(FilterCountFold<L>),
SumI64(SumI64Fold<L>),
Any(AnyFold<L>),
}Expand description
Enum-dispatch fold for common patterns that would otherwise use Box<dyn Fold>.
This is intentionally limited to a few hot, allocation-free cases so callers can avoid vtable dispatch in heterogeneous fold collections.
Variants§
Count(CountFold<L>)
Count every entry.
FilterCount(FilterCountFold<L>)
Count entries matching a predicate.
SumI64(SumI64Fold<L>)
Sum projected i64 values.
Any(AnyFold<L>)
Return whether any entry matches the predicate.
Implementations§
Source§impl<L> CommonFold<L>
impl<L> CommonFold<L>
Sourcepub fn filter_count(predicate: fn(&L) -> bool) -> Self
pub fn filter_count(predicate: fn(&L) -> bool) -> Self
Create a filtered-count common fold.
Sourcepub fn try_step(
&self,
state: CommonFoldState,
entry: &L,
context: &FoldContext,
) -> Result<CommonFoldState, FoldFailure>
pub fn try_step( &self, state: CommonFoldState, entry: &L, context: &FoldContext, ) -> Result<CommonFoldState, FoldFailure>
Process a single entry and return an error if the state shape is invalid.
Trait Implementations§
Source§impl<L: Clone> Clone for CommonFold<L>
impl<L: Clone> Clone for CommonFold<L>
Source§fn clone(&self) -> CommonFold<L>
fn clone(&self) -> CommonFold<L>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<L> Debug for CommonFold<L>
impl<L> Debug for CommonFold<L>
Source§impl<L> Fold<L, CommonFoldState> for CommonFold<L>
impl<L> Fold<L, CommonFoldState> for CommonFold<L>
Source§fn step(
&self,
state: CommonFoldState,
entry: &L,
context: &FoldContext,
) -> CommonFoldState
fn step( &self, state: CommonFoldState, entry: &L, context: &FoldContext, ) -> CommonFoldState
§Panics
Panics if state does not match the variant expected by self.
Use TryFold::try_step to handle the mismatch as an error instead.
Source§fn initial(&self, _context: &FoldContext) -> CommonFoldState
fn initial(&self, _context: &FoldContext) -> CommonFoldState
Get the initial state before any entries are processed.
Source§fn finalize(&self, state: S, _context: &FoldContext) -> S
fn finalize(&self, state: S, _context: &FoldContext) -> S
Finalize the state after all entries are processed. Read more
Source§fn 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. Read more
Source§fn 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.
Source§impl<L> TryFold<L, CommonFoldState> for CommonFold<L>
impl<L> TryFold<L, CommonFoldState> for CommonFold<L>
Source§fn try_step(
&self,
state: CommonFoldState,
entry: &L,
context: &FoldContext,
) -> Result<CommonFoldState, FoldFailure>
fn try_step( &self, state: CommonFoldState, entry: &L, context: &FoldContext, ) -> Result<CommonFoldState, FoldFailure>
Process a single entry and return an error instead of panicking.
Auto Trait Implementations§
impl<L> Freeze for CommonFold<L>
impl<L> RefUnwindSafe for CommonFold<L>
impl<L> Send for CommonFold<L>
impl<L> Sync for CommonFold<L>
impl<L> Unpin for CommonFold<L>
impl<L> UnsafeUnpin for CommonFold<L>
impl<L> UnwindSafe for CommonFold<L>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more