use crate::iter::plumbing::*; use crate::iter::Either::{Left, Right}; use crate::iter::*; /// `Either` is a parallel iterator if both `L` and `R` are parallel iterators. impl ParallelIterator for Either where L: ParallelIterator, R: ParallelIterator, { type Item = L::Item; fn drive_unindexed(self, consumer: C) -> C::Result where C: UnindexedConsumer, { match self { Left(iter) => iter.drive_unindexed(consumer), Right(iter) => iter.drive_unindexed(consumer), } } fn opt_len(&self) -> Option { self.as_ref().either(L::opt_len, R::opt_len) } } impl IndexedParallelIterator for Either where L: IndexedParallelIterator, R: IndexedParallelIterator, { fn drive(self, consumer: C) -> C::Result where C: Consumer, { match self { Left(iter) => iter.drive(consumer), Right(iter) => iter.drive(consumer), } } fn len(&self) -> usize { self.as_ref().either(L::len, R::len) } fn with_producer(self, callback: CB) -> CB::Output where CB: ProducerCallback, { match self { Left(iter) => iter.with_producer(callback), Right(iter) => iter.with_producer(callback), } } } /// `Either` can be extended if both `L` and `R` are parallel extendable. impl ParallelExtend for Either where L: ParallelExtend, R: ParallelExtend, T: Send, { fn par_extend(&mut self, par_iter: I) where I: IntoParallelIterator, { match self.as_mut() { Left(collection) => collection.par_extend(par_iter), Right(collection) => collection.par_extend(par_iter), } } }