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
use Transaction;
#[derive(Debug)]
#[must_use]
pub struct Branch3Builder<Tx>(Tx);
impl<Tx> Branch3Builder<Tx> {
pub fn new(tx: Tx) -> Self {
Branch3Builder(tx)
}
pub fn first<B, C>(self) -> Branch3<Tx, B, C> {
Branch3::B1(self.0)
}
pub fn second<B, C>(self) -> Branch3<B, Tx, C> {
Branch3::B2(self.0)
}
pub fn third<B, C>(self) -> Branch3<B, C, Tx> {
Branch3::B3(self.0)
}
}
#[derive(Debug)]
#[must_use]
pub enum Branch3<Tx1, Tx2, Tx3> {
B1(Tx1),
B2(Tx2),
B3(Tx3),
}
impl<Tx1, Tx2, Tx3> Transaction for Branch3<Tx1, Tx2, Tx3>
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,
>,
{
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 {
Branch3::B1(ref tx) => tx.run(ctx),
Branch3::B2(ref tx) => tx.run(ctx),
Branch3::B3(ref tx) => tx.run(ctx),
}
}
}