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
use std::marker::PhantomData;

use super::Pusherator;

variadics::variadic_trait! {
    /// A variadic list of Pusherators.
    pub variadic<T> PusheratorList where T: Pusherator {}
}

pub struct Demux<Func, Nexts, Item> {
    func: Func,
    nexts: Nexts,
    _phantom: PhantomData<fn(Item)>,
}
impl<Func, Nexts, Item> Pusherator for Demux<Func, Nexts, Item>
where
    Func: FnMut(Item, &mut Nexts),
    Nexts: PusheratorList,
{
    type Item = Item;
    fn give(&mut self, item: Self::Item) {
        (self.func)(item, &mut self.nexts);
    }
}
impl<Func, Nexts, Item> Demux<Func, Nexts, Item>
where
    Func: FnMut(Item, &mut Nexts),
    Nexts: PusheratorList,
{
    pub fn new(func: Func, nexts: Nexts) -> Self {
        Self {
            func,
            nexts,
            _phantom: PhantomData,
        }
    }
}