pub struct ConnPool<C: Poolable> { /* private fields */ }Expand description
Production-grade connection pool, generic over connection type C.
Hook safety: Lifecycle hooks must not call back into the pool (e.g.,
calling get() from inside a hook will deadlock). Hooks should be fast
and non-blocking.
Implementations§
Source§impl<C: Poolable> ConnPool<C>
impl<C: Poolable> ConnPool<C>
Sourcepub async fn new(
config: ConnPoolConfig,
hooks: LifecycleHooks<C>,
) -> Result<Arc<Self>, PoolError<C::Error>>
pub async fn new( config: ConnPoolConfig, hooks: LifecycleHooks<C>, ) -> Result<Arc<Self>, PoolError<C::Error>>
Create a new connection pool and spawn the maintenance task.
Sourcepub async fn get(self: &Arc<Self>) -> Result<PoolGuard<C>, PoolError<C::Error>>
pub async fn get(self: &Arc<Self>) -> Result<PoolGuard<C>, PoolError<C::Error>>
Check out a connection from the pool.
Sourcepub fn metrics(&self) -> PoolMetrics
pub fn metrics(&self) -> PoolMetrics
Get a snapshot of pool metrics.
Note: metrics are read from atomic counters without a global lock,
so values may be slightly inconsistent during high concurrency
(e.g., in_use could briefly exceed total). Use saturating_sub
for derived values.
Trait Implementations§
Auto Trait Implementations§
impl<C> !Freeze for ConnPool<C>
impl<C> !RefUnwindSafe for ConnPool<C>
impl<C> Send for ConnPool<C>
impl<C> Sync for ConnPool<C>
impl<C> Unpin for ConnPool<C>where
C: Unpin,
impl<C> UnsafeUnpin for ConnPool<C>
impl<C> !UnwindSafe for ConnPool<C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more