From 1b6a04ca5504955c571d1c97504fb45ea0befee4 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Mon, 8 Jan 2024 01:21:28 +0400 Subject: Initial vendor packages Signed-off-by: Valentin Popov --- vendor/rayon/src/par_either.rs | 74 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 vendor/rayon/src/par_either.rs (limited to 'vendor/rayon/src/par_either.rs') diff --git a/vendor/rayon/src/par_either.rs b/vendor/rayon/src/par_either.rs new file mode 100644 index 0000000..a19ce53 --- /dev/null +++ b/vendor/rayon/src/par_either.rs @@ -0,0 +1,74 @@ +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), + } + } +} -- cgit v1.2.3