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
use {IntoTransaction, Transaction};
pub fn map<Ctx, A, F, B>(a: A, f: F) -> Map<A::Tx, F>
where
A: IntoTransaction<Ctx>,
F: Fn(A::Item) -> B,
{
Map {
tx: a.into_transaction(),
f: f,
}
}
#[derive(Debug)]
#[must_use]
pub struct Map<Tx, F> {
tx: Tx,
f: F,
}
impl<Tx, U, F> Transaction for Map<Tx, F>
where
Tx: Transaction,
F: Fn(Tx::Item) -> U,
{
type Ctx = Tx::Ctx;
type Item = U;
type Err = Tx::Err;
fn run(&self, ctx: &mut Self::Ctx) -> Result<Self::Item, Self::Err> {
let &Map { ref tx, ref f } = self;
tx.run(ctx).map(f)
}
}