1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
use super::abstract_mut::AbstractMut; use super::tight::Tight; use rayon::iter::plumbing::{bridge, Consumer, ProducerCallback, UnindexedConsumer}; use rayon::iter::{IndexedParallelIterator, ParallelIterator}; #[allow(missing_docs)] pub struct ParTight<Storage>(Tight<Storage>); impl<Storage: AbstractMut> From<Tight<Storage>> for ParTight<Storage> { fn from(iter: Tight<Storage>) -> Self { ParTight(iter) } } impl<Storage: AbstractMut> ParallelIterator for ParTight<Storage> where Storage: Clone + Send, <Storage as AbstractMut>::Out: Send, { type Item = <Tight<Storage> as Iterator>::Item; fn drive_unindexed<C>(self, consumer: C) -> C::Result where C: UnindexedConsumer<Self::Item>, { bridge(self, consumer) } fn opt_len(&self) -> Option<usize> { Some(self.len()) } } impl<Storage: AbstractMut> IndexedParallelIterator for ParTight<Storage> where Storage: Clone + Send, <Storage as AbstractMut>::Out: Send, { fn len(&self) -> usize { self.0.len() } fn drive<C: Consumer<Self::Item>>(self, consumer: C) -> C::Result { bridge(self, consumer) } fn with_producer<CB: ProducerCallback<Self::Item>>(self, callback: CB) -> CB::Output { callback.callback(self.0) } }