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

pub struct Pivot<I, P>
where
    I: Iterator,
    P: Pusherator<Item = I::Item>,
{
    pull: I,
    push: P,
}
impl<I, P> Pivot<I, P>
where
    I: Iterator,
    P: Pusherator<Item = I::Item>,
{
    pub fn new(pull: I, push: P) -> Self {
        Self { pull, push }
    }

    pub fn step(&mut self) -> bool {
        if let Some(v) = self.pull.next() {
            self.push.give(v);
            true
        } else {
            false
        }
    }

    pub fn run(mut self) {
        for v in self.pull.by_ref() {
            self.push.give(v);
        }
    }
}

pub struct PivotBuild<I>
where
    I: Iterator,
{
    pull: I,
}
impl<I> PivotBuild<I>
where
    I: Iterator,
{
    pub fn new(pull: I) -> Self {
        Self { pull }
    }
}
impl<I> PusheratorBuild for PivotBuild<I>
where
    I: Iterator,
{
    type ItemOut = I::Item;

    type Output<O: Pusherator<Item = Self::ItemOut>> = Pivot<I, O>;
    fn push_to<O>(self, input: O) -> Self::Output<O>
    where
        O: Pusherator<Item = Self::ItemOut>,
    {
        Pivot {
            pull: self.pull,
            push: input,
        }
    }
}