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::FastAbstractMut;
use super::tight::FastTight;
use rayon::iter::plumbing::{bridge, Consumer, ProducerCallback, UnindexedConsumer};
use rayon::iter::{IndexedParallelIterator, ParallelIterator};

#[allow(missing_docs)]
pub struct FastParTight<Storage>(FastTight<Storage>);

impl<Storage: FastAbstractMut> From<FastTight<Storage>> for FastParTight<Storage> {
    fn from(iter: FastTight<Storage>) -> Self {
        FastParTight(iter)
    }
}

impl<Storage: FastAbstractMut> ParallelIterator for FastParTight<Storage>
where
    Storage: Clone + Send,
    <Storage as FastAbstractMut>::Out: Send,
{
    type Item = <FastTight<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: FastAbstractMut> IndexedParallelIterator for FastParTight<Storage>
where
    Storage: Clone + Send,
    <Storage as FastAbstractMut>::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)
    }
}