pub trait Connection: Executor {
// Required methods
fn connect(
url: Cow<'static, str>,
) -> impl Future<Output = Result<<Self::Driver as Driver>::Connection>>;
fn begin(&mut self) -> impl Future<Output = Result<impl Transaction<'_>>>;
// Provided method
fn disconnect(self) -> impl Future<Output = Result<()>> { ... }
}Expand description
A live database handle capable of executing queries and spawning transactions.
This trait extends Executor adding functionality to acquire a connection
and to begin transactional scopes.
Drivers implement concrete Connection types to expose backend-specific
behavior (timeouts, pooling strategies, prepared statement caching, etc.).
§Lifecycle
connectcreates (or fetches) an underlying connection. It may eagerly establish network I/O for validation; always await it.beginstarts a transaction returning an object implementingTransaction. Commit / rollback MUST be awaited to guarantee resource release.
Required Methods§
Sourcefn connect(
url: Cow<'static, str>,
) -> impl Future<Output = Result<<Self::Driver as Driver>::Connection>>
fn connect( url: Cow<'static, str>, ) -> impl Future<Output = Result<<Self::Driver as Driver>::Connection>>
Create a connection (or pool) with at least one underlying session established to the given URL.
Sourcefn begin(&mut self) -> impl Future<Output = Result<impl Transaction<'_>>>
fn begin(&mut self) -> impl Future<Output = Result<impl Transaction<'_>>>
Begin a transaction scope tied to the current connection.
Provided Methods§
fn disconnect(self) -> impl Future<Output = Result<()>>
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.