• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use super::plumbing::*;
2 use super::*;
3 
4 /// An [`IndexedParallelIterator`] that iterates over two parallel iterators of equal
5 /// length simultaneously.
6 ///
7 /// This struct is created by the [`zip_eq`] method on [`IndexedParallelIterator`],
8 /// see its documentation for more information.
9 ///
10 /// [`zip_eq`]: trait.IndexedParallelIterator.html#method.zip_eq
11 /// [`IndexedParallelIterator`]: trait.IndexedParallelIterator.html
12 #[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
13 #[derive(Debug, Clone)]
14 pub struct ZipEq<A: IndexedParallelIterator, B: IndexedParallelIterator> {
15     zip: Zip<A, B>,
16 }
17 
18 impl<A, B> ZipEq<A, B>
19 where
20     A: IndexedParallelIterator,
21     B: IndexedParallelIterator,
22 {
23     /// Creates a new `ZipEq` iterator.
new(a: A, b: B) -> Self24     pub(super) fn new(a: A, b: B) -> Self {
25         ZipEq {
26             zip: super::Zip::new(a, b),
27         }
28     }
29 }
30 
31 impl<A, B> ParallelIterator for ZipEq<A, B>
32 where
33     A: IndexedParallelIterator,
34     B: IndexedParallelIterator,
35 {
36     type Item = (A::Item, B::Item);
37 
drive_unindexed<C>(self, consumer: C) -> C::Result where C: UnindexedConsumer<Self::Item>,38     fn drive_unindexed<C>(self, consumer: C) -> C::Result
39     where
40         C: UnindexedConsumer<Self::Item>,
41     {
42         bridge(self.zip, consumer)
43     }
44 
opt_len(&self) -> Option<usize>45     fn opt_len(&self) -> Option<usize> {
46         Some(self.zip.len())
47     }
48 }
49 
50 impl<A, B> IndexedParallelIterator for ZipEq<A, B>
51 where
52     A: IndexedParallelIterator,
53     B: IndexedParallelIterator,
54 {
drive<C>(self, consumer: C) -> C::Result where C: Consumer<Self::Item>,55     fn drive<C>(self, consumer: C) -> C::Result
56     where
57         C: Consumer<Self::Item>,
58     {
59         bridge(self.zip, consumer)
60     }
61 
len(&self) -> usize62     fn len(&self) -> usize {
63         self.zip.len()
64     }
65 
with_producer<CB>(self, callback: CB) -> CB::Output where CB: ProducerCallback<Self::Item>,66     fn with_producer<CB>(self, callback: CB) -> CB::Output
67     where
68         CB: ProducerCallback<Self::Item>,
69     {
70         self.zip.with_producer(callback)
71     }
72 }
73