#[cfg(feature = "mdo")]
pub mod mdo;
pub mod prelude {
pub use super::Transaction;
pub use err::err;
pub use join_all::join_all;
pub use lazy::lazy;
pub use loop_fn::loop_fn;
pub use ok::ok;
pub use repeat::repeat;
pub use result::result;
pub use retry::retry;
pub use with_ctx::with_ctx;
}
mod then;
mod map;
mod and_then;
mod map_err;
mod or_else;
mod abort;
mod try_abort;
mod recover;
mod try_recover;
mod join;
mod join3;
mod join4;
mod branch;
mod branch3;
mod branch4;
mod loop_fn;
mod repeat;
mod retry;
mod result;
mod ok;
mod err;
mod lazy;
mod join_all;
mod with_ctx;
pub use abort::*;
pub use and_then::*;
pub use branch::*;
pub use branch3::*;
pub use branch4::*;
pub use err::*;
pub use join::*;
pub use join3::*;
pub use join4::*;
pub use join_all::*;
pub use lazy::*;
pub use loop_fn::*;
pub use map::*;
pub use map_err::*;
pub use ok::*;
pub use or_else::*;
pub use recover::*;
pub use repeat::*;
pub use result::*;
pub use retry::*;
pub use then::*;
pub use try_abort::*;
pub use try_recover::*;
pub use with_ctx::*;
#[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,
{
Box::new(self)
}
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,
{
then(self, f)
}
fn map<F, B>(self, f: F) -> Map<Self, F>
where
F: Fn(Self::Item) -> B,
Self: Sized,
{
map(self, f)
}
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,
{
and_then(self, f)
}
fn map_err<F, B>(self, f: F) -> MapErr<Self, F>
where
F: Fn(Self::Err) -> B,
Self: Sized,
{
map_err(self, f)
}
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,
{
or_else(self, f)
}
fn abort<T, F>(self, f: F) -> Abort<Self, T, F>
where
F: Fn(Self::Item) -> Self::Err,
Self: Sized,
{
abort(self, f)
}
fn try_abort<F, B>(self, f: F) -> TryAbort<Self, F, B>
where
F: Fn(Self::Item) -> Result<B, Self::Err>,
Self: Sized,
{
try_abort(self, f)
}
fn recover<T, F>(self, f: F) -> Recover<Self, T, F>
where
F: Fn(Self::Err) -> Self::Item,
Self: Sized,
{
recover(self, f)
}
fn try_recover<F, B>(self, f: F) -> TryRecover<Self, F, B>
where
F: Fn(Self::Err) -> Result<Self::Item, B>,
Self: Sized,
{
try_recover(self, f)
}
fn join<B>(self, b: B) -> Join<Self, B::Tx>
where
B: IntoTransaction<Self::Ctx, Err = Self::Err>,
Self: Sized,
{
join(self, b)
}
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,
{
join3(self, b, c)
}
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,
{
join4(self, b, c, d)
}
fn branch(self) -> BranchBuilder<Self>
where
Self: Sized,
{
BranchBuilder::new(self)
}
fn branch3(self) -> Branch3Builder<Self>
where
Self: Sized,
{
Branch3Builder::new(self)
}
fn branch4(self) -> Branch4Builder<Self>
where
Self: Sized,
{
Branch4Builder::new(self)
}
}
pub trait IntoTransaction<Ctx> {
type Tx: Transaction<Ctx = Ctx, Item = Self::Item, Err = Self::Err>;
type Err;
type Item;
fn into_transaction(self) -> Self::Tx;
}
impl<Tx, Ctx> IntoTransaction<Ctx> for Tx
where
Tx: Transaction<Ctx = Ctx>,
{
type Tx = Tx;
type Err = Tx::Err;
type Item = Tx::Item;
fn into_transaction(self) -> Self::Tx {
self
}
}
impl<Ctx, Tx1, Tx2> IntoTransaction<Ctx> for (Tx1, Tx2)
where
Tx1: IntoTransaction<Ctx>,
Tx2: IntoTransaction<Ctx, Err = Tx1::Err>,
{
type Tx = Join<Tx1::Tx, Tx2::Tx>;
type Err = Tx1::Err;
type Item = (Tx1::Item, Tx2::Item);
fn into_transaction(self) -> Self::Tx {
let (tx1, tx2) = self;
tx1.into_transaction().join(tx2.into_transaction())
}
}
impl<Ctx, Tx1, Tx2, Tx3> IntoTransaction<Ctx> for (Tx1, Tx2, Tx3)
where
Tx1: IntoTransaction<Ctx>,
Tx2: IntoTransaction<
Ctx,
Err = Tx1::Err,
>,
Tx3: IntoTransaction<
Ctx,
Err = Tx1::Err,
>,
{
type Tx = Join3<Tx1::Tx, Tx2::Tx, Tx3::Tx>;
type Err = Tx1::Err;
type Item = (Tx1::Item, Tx2::Item, Tx3::Item);
fn into_transaction(self) -> Self::Tx {
let (tx1, tx2, tx3) = self;
tx1.into_transaction().join3(
tx2.into_transaction(),
tx3.into_transaction(),
)
}
}
impl<Ctx, Tx1, Tx2, Tx3, Tx4> IntoTransaction<Ctx> for (Tx1, Tx2, Tx3, Tx4)
where
Tx1: IntoTransaction<Ctx>,
Tx2: IntoTransaction<
Ctx,
Err = Tx1::Err,
>,
Tx3: IntoTransaction<
Ctx,
Err = Tx1::Err,
>,
Tx4: IntoTransaction<
Ctx,
Err = Tx1::Err,
>,
{
type Tx = Join4<Tx1::Tx, Tx2::Tx, Tx3::Tx, Tx4::Tx>;
type Err = Tx1::Err;
type Item = (Tx1::Item, Tx2::Item, Tx3::Item, Tx4::Item);
fn into_transaction(self) -> Self::Tx {
let (tx1, tx2, tx3, tx4) = self;
tx1.into_transaction().join4(
tx2.into_transaction(),
tx3.into_transaction(),
tx4.into_transaction(),
)
}
}
impl<Ctx, T, E> IntoTransaction<Ctx> for Result<T, E>
where
T: Clone,
E: Clone,
{
type Tx = result::TxResult<Ctx, T, E>;
type Err = E;
type Item = T;
fn into_transaction(self) -> Self::Tx {
result::result(self)
}
}
impl<Ctx, T, E> Transaction for Fn(&mut Ctx) -> Result<T, E> {
type Ctx = Ctx;
type Item = T;
type Err = E;
fn run(&self, ctx: &mut Self::Ctx) -> Result<Self::Item, Self::Err> {
self(ctx)
}
}
impl<T> Transaction for Box<T>
where
T: ?Sized + Transaction,
{
type Ctx = T::Ctx;
type Item = T::Item;
type Err = T::Err;
fn run(&self, ctx: &mut Self::Ctx) -> Result<Self::Item, Self::Err> {
(**self).run(ctx)
}
}
impl<'a, T> Transaction for &'a T
where
T: ?Sized + Transaction,
{
type Ctx = T::Ctx;
type Item = T::Item;
type Err = T::Err;
fn run(&self, ctx: &mut Self::Ctx) -> Result<Self::Item, Self::Err> {
(**self).run(ctx)
}
}