Skip to main content

Executor

Trait Executor 

Source
pub trait Executor:
    Send
    + Sync
    + Debug {
    // Required methods
    fn family(&self) -> Family;
    fn fetch(
        &self,
        stmt: Statement,
    ) -> ExecFuture<'_, Result<Vec<Row>, ExecError>>;
    fn execute(
        &self,
        stmt: Statement,
    ) -> ExecFuture<'_, Result<ExecResult, ExecError>>;
}
Expand description

Anything that can run a built statement: a pool, a connection, a Transaction.

Object-safe on purpose — &dyn Executor is the currency application code, generated models and hooks trade in — and &self on purpose: exclusivity is the executor’s problem (a pool checks out per call; a transaction serialises behind a lock), not every call site’s. The promise is deliberately weak: each call runs on some connection. Only a connection or a transaction strengthens that to the same connection, which is why session state (SET, temp tables, advisory locks) through a bare pool is a bug.

Backends implement these three methods and nothing else here; every ergonomic path (Execute) funnels into them. New capabilities arrive as new opt-in traits (StreamExecutor is the template), never as added methods — adding a method here breaks every backend.

Required Methods§

Source

fn family(&self) -> Family

Which engine family this executor talks to.

Source

fn fetch(&self, stmt: Statement) -> ExecFuture<'_, Result<Vec<Row>, ExecError>>

Run a statement and collect every row — SELECT, or any mutation with RETURNING.

Source

fn execute( &self, stmt: Statement, ) -> ExecFuture<'_, Result<ExecResult, ExecError>>

Run a statement for its side effect.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<E: Executor + ?Sized> Executor for &E

Source§

impl<E: Executor + ?Sized> Executor for Arc<E>

Source§

impl<E: Executor + ?Sized> Executor for Box<E>

Implementors§