pusherator/
tee.rs

1use super::{Pusherator, PusheratorBuild};
2
3pub struct Tee<Next1, Next2> {
4    next1: Next1,
5    next2: Next2,
6}
7impl<Next1, Next2> Pusherator for Tee<Next1, Next2>
8where
9    Next1: Pusherator,
10    Next2: Pusherator<Item = Next1::Item>,
11    Next1::Item: Clone,
12{
13    type Item = Next1::Item;
14    fn give(&mut self, item: Self::Item) {
15        self.next1.give(item.clone());
16        self.next2.give(item);
17    }
18}
19impl<Next1, Next2> Tee<Next1, Next2>
20where
21    Next1: Pusherator,
22    Next2: Pusherator<Item = Next1::Item>,
23    Next1::Item: Clone,
24{
25    pub fn new(next1: Next1, next2: Next2) -> Self {
26        Self { next1, next2 }
27    }
28}
29
30pub struct TeeBuild<Prev, Next1>
31where
32    Prev: PusheratorBuild,
33    Next1: Pusherator<Item = Prev::ItemOut>,
34    Prev::ItemOut: Clone,
35{
36    prev: Prev,
37    next1: Next1,
38}
39impl<Prev, Next1> TeeBuild<Prev, Next1>
40where
41    Prev: PusheratorBuild,
42    Next1: Pusherator<Item = Prev::ItemOut>,
43    Prev::ItemOut: Clone,
44{
45    pub fn new(prev: Prev, next1: Next1) -> Self {
46        Self { prev, next1 }
47    }
48}
49impl<Prev, Next1> PusheratorBuild for TeeBuild<Prev, Next1>
50where
51    Prev: PusheratorBuild,
52    Next1: Pusherator<Item = Prev::ItemOut>,
53    Prev::ItemOut: Clone,
54{
55    type ItemOut = Prev::ItemOut;
56
57    type Output<Next: Pusherator<Item = Self::ItemOut>> = Prev::Output<Tee<Next1, Next>>;
58    fn push_to<Next>(self, input: Next) -> Self::Output<Next>
59    where
60        Next: Pusherator<Item = Self::ItemOut>,
61    {
62        self.prev.push_to(Tee::new(self.next1, input))
63    }
64}