pub trait ConnectionPool<D: Driver>: Debug {
// Required methods
fn get<'s>(&'s self) -> BoxFuture<'s, Result<PooledConnection<D>>>;
fn timeout_get<'s>(
&'s self,
timeout: Duration,
) -> BoxFuture<'s, Result<PooledConnection<D>>>;
fn detach<'s>(&'s self) -> BoxFuture<'s, Result<D::Connection>>;
fn resize(&self, max_size: usize) -> Result<()>;
fn into_box(self) -> Box<dyn ConnectionPool<D>>
where D: 'static;
fn close(self) -> BoxFuture<'static, Result<()>>;
}Expand description
A managed pool of reusable database connections.
Every method that yields connections produces a PooledConnection
that is automatically returned to the pool on drop, keeping the number
of open database connections bounded.
Required Methods§
Sourcefn get<'s>(&'s self) -> BoxFuture<'s, Result<PooledConnection<D>>>
fn get<'s>(&'s self) -> BoxFuture<'s, Result<PooledConnection<D>>>
Acquires a connection from the pool.
If all connections are in use and the pool is at its maximum size, this
call waits until one becomes available or the configured
[PoolConfig::wait_timeout] elapses, at which point an error is
returned.
Sourcefn timeout_get<'s>(
&'s self,
timeout: Duration,
) -> BoxFuture<'s, Result<PooledConnection<D>>>
fn timeout_get<'s>( &'s self, timeout: Duration, ) -> BoxFuture<'s, Result<PooledConnection<D>>>
Acquires a connection from the pool with an explicit timeout.
Identical to get but overrides the configured
wait timeout with timeout. Useful when individual call sites need
stricter or looser deadlines than the pool-level default.
Sourcefn detach<'s>(&'s self) -> BoxFuture<'s, Result<D::Connection>>
fn detach<'s>(&'s self) -> BoxFuture<'s, Result<D::Connection>>
Acquires a connection and removes it from pool management.
The returned D::Connection is a plain, pool-unaware connection. It
will not be returned to the pool when dropped, the underlying
database connection is closed instead. Use this when you need to hand
a connection to code that does not know about the pool, or when you
want to guarantee the connection is fully closed rather than recycled.
Sourcefn resize(&self, max_size: usize) -> Result<()>
fn resize(&self, max_size: usize) -> Result<()>
Changes the maximum number of connections the pool may hold.
Sourcefn into_box(self) -> Box<dyn ConnectionPool<D>>where
D: 'static,
fn into_box(self) -> Box<dyn ConnectionPool<D>>where
D: 'static,
Converts this pool into a sized type-erased Box<dyn ConnectionPool<D>>.
Driver::connect_pool returns an opaque impl ConnectionPool<D> type
that cannot be named or stored in struct fields, returned from trait
implementations, or otherwise used where a concrete named type is required.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".