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
69
70
71
72
73
74
75
use serde::{Deserialize, Serialize};
use std::marker::PhantomData;
use super::{ConsumerMulti, DistributedIteratorMulti};
#[must_use]
pub struct Cloned<I, T, Source> {
i: I,
marker: PhantomData<fn(Source, T)>,
}
impl<I, T, Source> Cloned<I, T, Source> {
pub(super) fn new(i: I) -> Self {
Self {
i,
marker: PhantomData,
}
}
}
impl<'a, I, Source, T: 'a> DistributedIteratorMulti<&'a Source> for Cloned<I, T, Source>
where
I: DistributedIteratorMulti<&'a Source, Item = &'a T>,
T: Clone,
{
type Item = T;
type Task = ClonedConsumer<I::Task>;
fn task(&self) -> Self::Task {
let task = self.i.task();
ClonedConsumer { task }
}
}
#[derive(Serialize, Deserialize)]
pub struct ClonedConsumer<T> {
task: T,
}
impl<'a, C, Source, T: 'a> ConsumerMulti<&'a Source> for ClonedConsumer<C>
where
C: ConsumerMulti<&'a Source, Item = &'a T>,
T: Clone,
{
type Item = T;
fn run(&self, source: &'a Source, i: &mut impl FnMut(Self::Item) -> bool) -> bool {
self.task.run(source, &mut |item| i(item.clone()))
}
}