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