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
use super::{Pusherator, PusheratorBuild};

pub struct Inspect<Next, Func> {
    next: Next,
    func: Func,
}
impl<Next, Func> Pusherator for Inspect<Next, Func>
where
    Next: Pusherator,
    Func: FnMut(&Next::Item),
{
    type Item = Next::Item;

    fn give(&mut self, item: Self::Item) {
        (self.func)(&item);
        self.next.give(item);
    }
}
impl<Next, Func> Inspect<Next, Func>
where
    Next: Pusherator,
    Func: FnMut(&Next::Item),
{
    pub fn new(func: Func, next: Next) -> Self {
        Self { next, func }
    }
}

pub struct InspectBuild<Prev, Func> {
    prev: Prev,
    func: Func,
}
impl<Prev, Func> InspectBuild<Prev, Func>
where
    Prev: PusheratorBuild,
    Func: FnMut(&Prev::ItemOut),
{
    pub fn new(prev: Prev, func: Func) -> Self {
        Self { prev, func }
    }
}
impl<Prev, Func> PusheratorBuild for InspectBuild<Prev, Func>
where
    Prev: PusheratorBuild,
    Func: FnMut(&Prev::ItemOut),
{
    type ItemOut = Prev::ItemOut;

    type Output<Next: Pusherator<Item = Self::ItemOut>> = Prev::Output<Inspect<Next, Func>>;
    fn push_to<Next>(self, next: Next) -> Self::Output<Next>
    where
        Next: Pusherator<Item = Self::ItemOut>,
    {
        self.prev.push_to(Inspect::new(self.func, next))
    }
}