rayon::iter::plumbing

Trait Folder

Source
pub trait Folder<Item>: Sized {
    type Result;

    // Required methods
    fn consume(self, item: Item) -> Self;
    fn complete(self) -> Self::Result;
    fn full(&self) -> bool;

    // Provided method
    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§

Source

type Result

The type of result that will ultimately be produced by the folder.

Required Methods§

Source

fn consume(self, item: Item) -> Self

Consume next item and return new sequential state.

Source

fn complete(self) -> Self::Result

Finish consuming items, produce final result.

Source

fn full(&self) -> bool

Hint whether this Folder would like to stop processing further items, e.g. if a search has been completed.

Provided Methods§

Source

fn consume_iter<I>(self, iter: I) -> Self
where 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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§