pub trait Folder<Item>: Sized {
type Result;
fn consume(self, item: Item) -> Self;
fn complete(self) -> Self::Result;
fn full(&self) -> bool;
fn consume_iter<I>(self, iter: I) -> Self
where
I: IntoIterator<Item = Item>,
{ ... }
}
Expand description
The Folder
trait encapsulates the standard fold
operation. It can be fed many items using the consume
method. At the end, once all items have been consumed, it can then
be converted (using complete
) into a final value.
Required Associated Types
Required Methods
Provided Methods
sourcefn consume_iter<I>(self, iter: I) -> Selfwhere
I: IntoIterator<Item = Item>,
fn consume_iter<I>(self, iter: I) -> Selfwhere
I: IntoIterator<Item = Item>,
Consume items from the iterator until full, and return new sequential state.
This method is optional. The default simply iterates over
iter
, invoking consume
and checking after each iteration
whether full
returns false.
The main reason to override it is if you can provide a more specialized, efficient implementation.