Skip to main content

moirai_iter/parallel/traits/
consumer.rs

1use super::iterator::ParallelIterator;
2
3/// Consumer trait for parallel iterator operations.
4pub trait Consumer<T>: Send + Sync {
5    /// Result type produced by consuming an iterator.
6    type Result: Send;
7
8    /// Consume items from a parallel iterator.
9    fn consume<I>(self, iter: I) -> Self::Result
10    where
11        I: ParallelIterator<Item = T>;
12
13    /// Split the consumer for parallel processing.
14    fn split_at(self, index: usize) -> (Self, Self)
15    where
16        Self: Sized;
17
18    /// Combine results from split consumers.
19    fn combine(left: Self::Result, right: Self::Result) -> Self::Result;
20}
21
22/// Trait for collections that can be extended in parallel.
23pub trait ParallelExtend<T>: Send {
24    /// Extend the collection with items from a parallel iterator.
25    fn par_extend<I>(&mut self, par_iter: I)
26    where
27        I: ParallelIterator<Item = T>;
28}