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
67
68
69
70
71
use Transaction;

/// Branch4Builder
#[derive(Debug)]
#[must_use]
pub struct Branch4Builder<Tx>(Tx);

impl<Tx> Branch4Builder<Tx> {
    pub fn new(tx: Tx) -> Self {
        Branch4Builder(tx)
    }

    pub fn first<B, C, D>(self) -> Branch4<Tx, B, C, D> {
        Branch4::B1(self.0)
    }

    pub fn second<B, C, D>(self) -> Branch4<B, Tx, C, D> {
        Branch4::B2(self.0)
    }

    pub fn third<B, C, D>(self) -> Branch4<B, C, Tx, D> {
        Branch4::B3(self.0)
    }

    pub fn fourth<B, C, D>(self) -> Branch4<B, C, D, Tx> {
        Branch4::B4(self.0)
    }
}


/// The result of `branch4`
#[derive(Debug)]
#[must_use]
pub enum Branch4<Tx1, Tx2, Tx3, Tx4> {
    B1(Tx1),
    B2(Tx2),
    B3(Tx3),
    B4(Tx4),
}

impl<Tx1, Tx2, Tx3, Tx4> Transaction for Branch4<Tx1, Tx2, Tx3, Tx4>
where
    Tx1: Transaction,
    Tx2: Transaction<
        Ctx = Tx1::Ctx,
        Item = Tx1::Item,
        Err = Tx1::Err,
    >,
    Tx3: Transaction<
        Ctx = Tx1::Ctx,
        Item = Tx1::Item,
        Err = Tx1::Err,
    >,
    Tx4: Transaction<
        Ctx = Tx1::Ctx,
        Item = Tx1::Item,
        Err = Tx1::Err,
    >,
{
    type Ctx = Tx1::Ctx;
    type Item = Tx1::Item;
    type Err = Tx1::Err;
    fn run(&self, ctx: &mut Self::Ctx) -> Result<Self::Item, Self::Err> {
        match *self {
            Branch4::B1(ref tx) => tx.run(ctx),
            Branch4::B2(ref tx) => tx.run(ctx),
            Branch4::B3(ref tx) => tx.run(ctx),
            Branch4::B4(ref tx) => tx.run(ctx),
        }
    }
}