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
use core::{
    fmt::{self, Debug, Display, Formatter},
    marker::PhantomData,
};

/// A pipeline type where two fields have a parent-child/first-second relationship
pub struct Pipeline<F, S, M = ()> {
    pub first: F,
    pub second: S,
    _marker: PhantomData<M>,
}

impl<F, S, M> Pipeline<F, S, M> {
    pub const fn new(first: F, second: S) -> Self {
        Self {
            first,
            second,
            _marker: PhantomData,
        }
    }
}

impl<F, S, M> Clone for Pipeline<F, S, M>
where
    F: Clone,
    S: Clone,
{
    fn clone(&self) -> Self {
        Self {
            first: self.first.clone(),
            second: self.second.clone(),
            _marker: PhantomData,
        }
    }
}

impl<F, S, M> Debug for Pipeline<F, S, M>
where
    F: Debug,
    S: Debug,
{
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        f.debug_struct("Pipeline")
            .field("first", &self.first)
            .field("second", &self.second)
            .finish()
    }
}

impl<F, S, M> Display for Pipeline<F, S, M>
where
    F: Display,
    S: Display,
{
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        write!(f, "{}, {}", self.first, self.second)
    }
}