Trait transaction::Transaction
[−]
[src]
#[must_use]pub trait Transaction { type Ctx; type Item; type Err; fn run(&self, ctx: &mut Self::Ctx) -> Result<Self::Item, Self::Err>; fn boxed<'a>(
self
) -> Box<Transaction<Ctx = Self::Ctx, Item = Self::Item, Err = Self::Err> + 'a>
where
Self: Sized + 'a, { ... } fn then<F, B, Tx2>(self, f: F) -> Then<Self, F, Tx2>
where
Tx2: IntoTransaction<Self::Ctx, Item = B, Err = Self::Err>,
F: Fn(Result<Self::Item, Self::Err>) -> Tx2,
Self: Sized, { ... } fn map<F, B>(self, f: F) -> Map<Self, F>
where
F: Fn(Self::Item) -> B,
Self: Sized, { ... } fn and_then<F, B>(self, f: F) -> AndThen<Self, F, B>
where
B: IntoTransaction<Self::Ctx, Err = Self::Err>,
F: Fn(Self::Item) -> B,
Self: Sized, { ... } fn map_err<F, B>(self, f: F) -> MapErr<Self, F>
where
F: Fn(Self::Err) -> B,
Self: Sized, { ... } fn or_else<F, B>(self, f: F) -> OrElse<Self, F, B>
where
B: IntoTransaction<Self::Ctx, Item = Self::Item>,
F: Fn(Self::Err) -> B,
Self: Sized, { ... } fn abort<T, F>(self, f: F) -> Abort<Self, T, F>
where
F: Fn(Self::Item) -> Self::Err,
Self: Sized, { ... } fn try_abort<F, B>(self, f: F) -> TryAbort<Self, F, B>
where
F: Fn(Self::Item) -> Result<B, Self::Err>,
Self: Sized, { ... } fn recover<T, F>(self, f: F) -> Recover<Self, T, F>
where
F: Fn(Self::Item) -> Self::Err,
Self: Sized, { ... } fn try_recover<F, B>(self, f: F) -> TryRecover<Self, F, B>
where
F: Fn(Self::Item) -> Result<B, Self::Err>,
Self: Sized, { ... } fn join<B>(self, b: B) -> Join<Self, B::Tx>
where
B: IntoTransaction<Self::Ctx, Err = Self::Err>,
Self: Sized, { ... } fn join3<B, C>(self, b: B, c: C) -> Join3<Self, B::Tx, C::Tx>
where
B: IntoTransaction<Self::Ctx, Err = Self::Err>,
C: IntoTransaction<Self::Ctx, Err = Self::Err>,
Self: Sized, { ... } fn join4<B, C, D>(
self,
b: B,
c: C,
d: D
) -> Join4<Self, B::Tx, C::Tx, D::Tx>
where
B: IntoTransaction<Self::Ctx, Err = Self::Err>,
C: IntoTransaction<Self::Ctx, Err = Self::Err>,
D: IntoTransaction<Self::Ctx, Err = Self::Err>,
Self: Sized, { ... } fn branch(self) -> BranchBuilder<Self>
where
Self: Sized, { ... } fn branch3(self) -> Branch3Builder<Self>
where
Self: Sized, { ... } fn branch4(self) -> Branch4Builder<Self>
where
Self: Sized, { ... } }
An abstract transaction. Transactions sharing the same Ctx
can be
composed with combinators. When the transaction return an error, it means
the transaction is failed. Some runners may abort the transaction and the
other may retry the computation. Thus all the computation should be
idempotent (of cause, except operations using context). Note that this
transaction is not executed until it is run
.
Associated Types
type Ctx
The contxt type (i.e. transaction type) of the transaction
type Item
The return type of the transaction
type Err
The error type of the transaction
Required Methods
fn run(&self, ctx: &mut Self::Ctx) -> Result<Self::Item, Self::Err>
Run the transaction. This will called by transaction runner rather than user by hand.
Provided Methods
fn boxed<'a>(
self
) -> Box<Transaction<Ctx = Self::Ctx, Item = Self::Item, Err = Self::Err> + 'a> where
Self: Sized + 'a,
self
) -> Box<Transaction<Ctx = Self::Ctx, Item = Self::Item, Err = Self::Err> + 'a> where
Self: Sized + 'a,
Box the transaction
fn then<F, B, Tx2>(self, f: F) -> Then<Self, F, Tx2> where
Tx2: IntoTransaction<Self::Ctx, Item = B, Err = Self::Err>,
F: Fn(Result<Self::Item, Self::Err>) -> Tx2,
Self: Sized,
Tx2: IntoTransaction<Self::Ctx, Item = B, Err = Self::Err>,
F: Fn(Result<Self::Item, Self::Err>) -> Tx2,
Self: Sized,
Take the previous result of computation and do another computation
fn map<F, B>(self, f: F) -> Map<Self, F> where
F: Fn(Self::Item) -> B,
Self: Sized,
F: Fn(Self::Item) -> B,
Self: Sized,
Transform the previous successful value
fn and_then<F, B>(self, f: F) -> AndThen<Self, F, B> where
B: IntoTransaction<Self::Ctx, Err = Self::Err>,
F: Fn(Self::Item) -> B,
Self: Sized,
B: IntoTransaction<Self::Ctx, Err = Self::Err>,
F: Fn(Self::Item) -> B,
Self: Sized,
Take the previous successful value of computation and do another computation
fn map_err<F, B>(self, f: F) -> MapErr<Self, F> where
F: Fn(Self::Err) -> B,
Self: Sized,
F: Fn(Self::Err) -> B,
Self: Sized,
Transform the previous error value
fn or_else<F, B>(self, f: F) -> OrElse<Self, F, B> where
B: IntoTransaction<Self::Ctx, Item = Self::Item>,
F: Fn(Self::Err) -> B,
Self: Sized,
B: IntoTransaction<Self::Ctx, Item = Self::Item>,
F: Fn(Self::Err) -> B,
Self: Sized,
Take the previous error value of computation and do another computation. This may be used falling back
fn abort<T, F>(self, f: F) -> Abort<Self, T, F> where
F: Fn(Self::Item) -> Self::Err,
Self: Sized,
F: Fn(Self::Item) -> Self::Err,
Self: Sized,
Take the previous successfull value of computation and abort the transaction.
fn try_abort<F, B>(self, f: F) -> TryAbort<Self, F, B> where
F: Fn(Self::Item) -> Result<B, Self::Err>,
Self: Sized,
F: Fn(Self::Item) -> Result<B, Self::Err>,
Self: Sized,
Try to abort the transaction
fn recover<T, F>(self, f: F) -> Recover<Self, T, F> where
F: Fn(Self::Item) -> Self::Err,
Self: Sized,
F: Fn(Self::Item) -> Self::Err,
Self: Sized,
Recover from an error
fn try_recover<F, B>(self, f: F) -> TryRecover<Self, F, B> where
F: Fn(Self::Item) -> Result<B, Self::Err>,
Self: Sized,
F: Fn(Self::Item) -> Result<B, Self::Err>,
Self: Sized,
Try to recover from an error
fn join<B>(self, b: B) -> Join<Self, B::Tx> where
B: IntoTransaction<Self::Ctx, Err = Self::Err>,
Self: Sized,
B: IntoTransaction<Self::Ctx, Err = Self::Err>,
Self: Sized,
join 2 indepndant transactions
fn join3<B, C>(self, b: B, c: C) -> Join3<Self, B::Tx, C::Tx> where
B: IntoTransaction<Self::Ctx, Err = Self::Err>,
C: IntoTransaction<Self::Ctx, Err = Self::Err>,
Self: Sized,
B: IntoTransaction<Self::Ctx, Err = Self::Err>,
C: IntoTransaction<Self::Ctx, Err = Self::Err>,
Self: Sized,
join 3 indepndant transactions
fn join4<B, C, D>(self, b: B, c: C, d: D) -> Join4<Self, B::Tx, C::Tx, D::Tx> where
B: IntoTransaction<Self::Ctx, Err = Self::Err>,
C: IntoTransaction<Self::Ctx, Err = Self::Err>,
D: IntoTransaction<Self::Ctx, Err = Self::Err>,
Self: Sized,
B: IntoTransaction<Self::Ctx, Err = Self::Err>,
C: IntoTransaction<Self::Ctx, Err = Self::Err>,
D: IntoTransaction<Self::Ctx, Err = Self::Err>,
Self: Sized,
join 4 indepndant transactions
fn branch(self) -> BranchBuilder<Self> where
Self: Sized,
Self: Sized,
branch builder
fn branch3(self) -> Branch3Builder<Self> where
Self: Sized,
Self: Sized,
3 branch builder
fn branch4(self) -> Branch4Builder<Self> where
Self: Sized,
Self: Sized,
4 branch builder
Implementors
impl<Tx, Tx2, F> Transaction for Then<Tx, F, Tx2> where
Tx2: IntoTransaction<Tx::Ctx, Err = Tx::Err>,
Tx: Transaction,
F: Fn(Result<Tx::Item, Tx::Err>) -> Tx2,impl<Tx, U, F> Transaction for Map<Tx, F> where
Tx: Transaction,
F: Fn(Tx::Item) -> U,impl<Tx, Tx2, F> Transaction for AndThen<Tx, F, Tx2> where
Tx2: IntoTransaction<Tx::Ctx, Err = Tx::Err>,
Tx: Transaction,
F: Fn(Tx::Item) -> Tx2,impl<E, Tx, F> Transaction for MapErr<Tx, F> where
Tx: Transaction,
F: Fn(Tx::Err) -> E,impl<Tx, Tx2, F> Transaction for OrElse<Tx, F, Tx2> where
Tx2: IntoTransaction<Tx::Ctx, Item = Tx::Item, Err = Tx::Err>,
Tx: Transaction,
F: Fn(Tx::Err) -> Tx2,impl<Tx, F, T> Transaction for Abort<Tx, T, F> where
Tx: Transaction,
F: Fn(Tx::Item) -> Tx::Err,impl<Tx, F, B> Transaction for TryAbort<Tx, F, B> where
Tx: Transaction,
F: Fn(Tx::Item) -> Result<B, Tx::Err>,impl<Tx, F, T> Transaction for Recover<Tx, T, F> where
Tx: Transaction,
F: Fn(Tx::Err) -> Tx::Item,impl<Tx, F, B> Transaction for TryRecover<Tx, F, B> where
Tx: Transaction,
F: Fn(Tx::Err) -> Result<Tx::Item, B>,impl<Tx1, Tx2> Transaction for Join<Tx1, Tx2> where
Tx1: Transaction,
Tx2: Transaction<Ctx = Tx1::Ctx, Err = Tx1::Err>,impl<Tx1, Tx2, Tx3> Transaction for Join3<Tx1, Tx2, Tx3> where
Tx1: Transaction,
Tx2: Transaction<Ctx = Tx1::Ctx, Err = Tx1::Err>,
Tx3: Transaction<Ctx = Tx1::Ctx, Err = Tx1::Err>,impl<Tx1, Tx2, Tx3, Tx4> Transaction for Join4<Tx1, Tx2, Tx3, Tx4> where
Tx1: Transaction,
Tx2: Transaction<Ctx = Tx1::Ctx, Err = Tx1::Err>,
Tx3: Transaction<Ctx = Tx1::Ctx, Err = Tx1::Err>,
Tx4: Transaction<Ctx = Tx1::Ctx, Err = Tx1::Err>,impl<Tx1, Tx2> Transaction for Branch<Tx1, Tx2> where
Tx1: Transaction,
Tx2: Transaction<Ctx = Tx1::Ctx, Item = Tx1::Item, Err = Tx1::Err>,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>,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>,impl<Ctx, S, T, F, A> Transaction for LoopFn<Ctx, F, A> where
F: Fn(S) -> A,
A: IntoTransaction<Ctx, Item = Loop<S, T>>,impl<Ctx, F, Tx> Transaction for Repeat<Ctx, F, Tx> where
F: Fn(usize) -> Tx,
Tx: IntoTransaction<Ctx>,impl<Ctx, F, Tx> Transaction for Retry<Ctx, F, Tx> where
F: Fn(usize) -> Tx,
Tx: IntoTransaction<Ctx>,impl<Ctx, T, E> Transaction for TxResult<Ctx, T, E> where
T: Clone,
E: Clone,impl<Ctx, T, E> Transaction for TxOk<Ctx, T, E> where
T: Clone,impl<Ctx, T, E> Transaction for TxErr<Ctx, T, E> where
E: Clone,impl<Ctx, T, E, F> Transaction for Lazy<Ctx, F> where
F: Fn() -> Result<T, E>,impl<Tx> Transaction for JoinAll<Tx> where
Tx: Transaction,impl<Ctx, T, E, F> Transaction for WithCtx<Ctx, F> where
F: Fn(&mut Ctx) -> Result<T, E>,impl<Ctx, T, E> Transaction for Fn(&mut Ctx) -> Result<T, E>
impl<T: ?Sized> Transaction for Box<T> where
T: Transaction,impl<'a, T: ?Sized> Transaction for &'a T where
T: Transaction,