pub struct ConnectionPool<T> { /* private fields */ }Expand description
A minimal database connection pool.
Maintains a bounded set of connections and hands them out on request. When all connections are in use, callers block until one is returned (or a timeout expires).
Connections are returned automatically when the PooledConnection guard
is dropped, so callers cannot accidentally leak a slot.
Implementations§
Source§impl<T> ConnectionPool<T>
impl<T> ConnectionPool<T>
Sourcepub fn new(max_size: usize) -> Self
pub fn new(max_size: usize) -> Self
Create a new, empty pool with the given capacity.
Connections must be added via [add] before they can be acquired.
Sourcepub fn add(&self, conn: T)
pub fn add(&self, conn: T)
Add a connection to the pool.
Panics if the pool is already at capacity.
Sourcepub fn get(
&self,
timeout: Duration,
) -> Result<PooledConnection<'_, T>, PoolError>
pub fn get( &self, timeout: Duration, ) -> Result<PooledConnection<'_, T>, PoolError>
Acquire a connection, blocking up to timeout.
Returns Err if the timeout expires before a connection becomes
available.
Sourcepub fn available_count(&self) -> usize
pub fn available_count(&self) -> usize
Number of connections currently idle in the pool.
Auto Trait Implementations§
impl<T> !Freeze for ConnectionPool<T>
impl<T> RefUnwindSafe for ConnectionPool<T>
impl<T> Send for ConnectionPool<T>where
T: Send,
impl<T> Sync for ConnectionPool<T>where
T: Send,
impl<T> Unpin for ConnectionPool<T>where
T: Unpin,
impl<T> UnsafeUnpin for ConnectionPool<T>
impl<T> UnwindSafe for ConnectionPool<T>
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