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