TransactionRunner

Trait TransactionRunner 

Source
pub trait TransactionRunner<'p, Repos>: Sized {
    type Tx: TransactionOps;
    type DbError: StdError + Send + Sync;

    // Required method
    async fn run<F, Fut, T, E>(self, f: F) -> Result<T, E>
       where F: FnOnce(TransactionContext<'_, Self::Tx, Repos>) -> Fut + Send,
             Fut: Future<Output = Result<T, E>> + Send,
             E: From<TransactionError<Self::DbError>>;
}
Expand description

Trait for executing operations within a transaction.

This trait is implemented on Transaction with specific repository combinations, enabling type-safe execution.

Required Associated Types§

Source

type Tx: TransactionOps

Transaction type.

Source

type DbError: StdError + Send + Sync

Database error type.

Required Methods§

Source

async fn run<F, Fut, T, E>(self, f: F) -> Result<T, E>
where F: FnOnce(TransactionContext<'_, Self::Tx, Repos>) -> Fut + Send, Fut: Future<Output = Result<T, E>> + Send, E: From<TransactionError<Self::DbError>>,

Execute a closure within the transaction.

Automatically commits on Ok, rolls back on Err or panic.

§Type Parameters
  • F — Closure type
  • Fut — Future returned by closure
  • T — Success type
  • E — Error type (must be convertible from database error)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§