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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use iter::plumbing::*;
use iter::*;
pub fn once<T: Send>(item: T) -> Once<T> {
Once { item }
}
#[derive(Clone, Debug)]
pub struct Once<T: Send> {
item: T,
}
impl<T: Send> ParallelIterator for Once<T> {
type Item = T;
fn drive_unindexed<C>(self, consumer: C) -> C::Result
where
C: UnindexedConsumer<Self::Item>,
{
self.drive(consumer)
}
fn opt_len(&self) -> Option<usize> {
Some(1)
}
}
impl<T: Send> IndexedParallelIterator for Once<T> {
fn drive<C>(self, consumer: C) -> C::Result
where
C: Consumer<Self::Item>,
{
consumer.into_folder().consume(self.item).complete()
}
fn len(&self) -> usize {
1
}
fn with_producer<CB>(self, callback: CB) -> CB::Output
where
CB: ProducerCallback<Self::Item>,
{
Some(self.item).into_par_iter().with_producer(callback)
}
}