Skip to main content

BeginWith

Trait BeginWith 

Source
pub trait BeginWith: Begin {
    // Required method
    fn begin_with(
        &self,
        opts: TxOptions,
    ) -> ExecFuture<'_, Result<Transaction, ExecError>>;
}
Expand description

Opt-in transaction options: begin_with beside begin.

A separate trait rather than a second method on Begin, following the StreamExecutor template: the core traits never grow methods, so a backend that has no answer for isolation levels stays compiling and stays honest by not implementing this.

let tx = db.begin_with(Isolation::Serializable.into()).await?;
let tx = db.begin_with(TxOptions::new().isolation(Isolation::RepeatableRead).read_only()).await?;

Implementing it is three lines: refuse the options for this family (TxOptions::check) before taking a connection, then hand the connection to Transaction::begin_on_with, which owns the SQL.

Required Methods§

Source

fn begin_with( &self, opts: TxOptions, ) -> ExecFuture<'_, Result<Transaction, ExecError>>

Open a transaction with explicit options.

Options this engine cannot honour are an error — never a silent downgrade, never a no-op. TxOptions::plan is the table of what each engine accepts and why.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<B: BeginWith + ?Sized> BeginWith for &B

Source§

impl<B: BeginWith + ?Sized> BeginWith for Arc<B>

Implementors§