gix_features::parallel::reduce

Trait Reduce

source
pub trait Reduce {
    type Input;
    type FeedProduce;
    type Output;
    type Error;

    // Required methods
    fn feed(
        &mut self,
        item: Self::Input,
    ) -> Result<Self::FeedProduce, Self::Error>;
    fn finalize(self) -> Result<Self::Output, Self::Error>;
}
Expand description

An trait for aggregating items commonly produced in threads into a single result, without itself needing to be thread safe.

Required Associated Types§

source

type Input

The type fed to the reducer in the feed() method.

It’s produced by a function that may run on multiple threads.

source

type FeedProduce

The type produced in Ok(…) by feed(). Most reducers by nature use () here as the value is in the aggregation. However, some may use it to collect statistics only and return their Input in some form as a result here for Stepwise to be useful.

source

type Output

The type produced once by the finalize() method.

For traditional reducers, this is the value produced by the entire operation. For those made for step-wise iteration this may be aggregated statistics.

source

type Error

The error type to use for all methods of this trait.

Required Methods§

source

fn feed(&mut self, item: Self::Input) -> Result<Self::FeedProduce, Self::Error>

Called each time a new item was produced in order to aggregate it into the final result.

If an Error is returned, the entire operation will be stopped.

source

fn finalize(self) -> Result<Self::Output, Self::Error>

Called once once all items where passed to feed(), producing the final Output of the operation or an Error.

Implementors§

source§

impl<Input, Error> Reduce for IdentityWithResult<Input, Error>

source§

type Input = Result<Input, <IdentityWithResult<Input, Error> as Reduce>::Error>

source§

type FeedProduce = Input

source§

type Output = ()

source§

type Error = Error