pub trait Manage:
Send
+ Sync
+ 'static {
type Connection: 'static;
type Error;
// Required methods
fn connect(
&self,
) -> impl Future<Output = Result<Self::Connection, Self::Error>>;
fn recycle(
&self,
conn: &mut Self::Connection,
meta: &SlotMeta,
) -> impl Future<Output = Result<(), Self::Error>>;
// Provided method
fn disconnect(&self, conn: Self::Connection) { ... }
}Expand description
Creates and validates connections for a Pool.
This is the trait you implement for your protocol (Postgres, Redis, an HTTP client, …).
§Why there are no Send bounds on the futures
compio is a completion-based, thread-per-core runtime: its IO handles are
bound to the driver of the thread that created them and are !Send. A pool
built on bb8’s trait shape cannot hold a compio::net::TcpStream at all,
because bb8 requires Connection: Send.
So Manage requires Send + Sync on the manager (it is shared across
threads inside the pool handle) but places no bounds whatsoever on
Connection or on the returned futures. Connections
live in thread-local shards and never cross a thread boundary unless you
additionally implement Detach.
Required Associated Types§
Sourcetype Connection: 'static
type Connection: 'static
The pooled resource. May be !Send; must be owned ('static),
since shards are stored in thread-local slots.
Required Methods§
Sourcefn connect(&self) -> impl Future<Output = Result<Self::Connection, Self::Error>>
fn connect(&self) -> impl Future<Output = Result<Self::Connection, Self::Error>>
Establishes a new connection.
Called on the thread that will own the connection, so it is safe (and
expected) to touch the current compio runtime here.
Sourcefn recycle(
&self,
conn: &mut Self::Connection,
meta: &SlotMeta,
) -> impl Future<Output = Result<(), Self::Error>>
fn recycle( &self, conn: &mut Self::Connection, meta: &SlotMeta, ) -> impl Future<Output = Result<(), Self::Error>>
Prepares a previously-used connection for hand-off.
Called on acquire, not on return, because returning happens in Drop,
which cannot await. Use it for a cheap liveness check and to reset
protocol state (roll back an open transaction, drain a pipeline).
Returning Err discards the connection; the pool then transparently
tries the next idle one or opens a fresh connection.
Provided Methods§
Sourcefn disconnect(&self, conn: Self::Connection)
fn disconnect(&self, conn: Self::Connection)
Called before a connection is dropped, for graceful shutdown.
The default is a no-op: dropping the connection closes it. Override this
only for protocols with an explicit goodbye message (Redis QUIT,
Postgres Terminate). It is synchronous by design — it runs from Drop
paths and during thread teardown, where awaiting is not possible.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".