Skip to main content

AsyncConnectionPool

Struct AsyncConnectionPool 

Source
pub struct AsyncConnectionPool<T, F>(/* private fields */);
Expand description

A tokio-based, cancel-safe connection pool. Cheaply clonable (clones share one pool).

Implementations§

Source§

impl<T, F> AsyncConnectionPool<T, F>
where T: Clone + Eq + Hash + Send + Sync + 'static, F: AsyncConnectionFactory<T> + 'static,

Source

pub fn new( factory: F, config: PoolConfig, options: Option<PoolOptions<T>>, ) -> Result<Self, PoolError>

Builds an async pool, validating config.

Source

pub fn name(&self) -> &str

The pool’s name.

Source

pub async fn open(&self) -> Result<(), PoolError>

Warms up min_size connections and starts background maintenance. Idempotent.

Source

pub async fn close(&self, timeout: Option<f64>)

Closes idle connections now; checked-out ones close on release. Idempotent. timeout (None = don’t wait) drains gracefully up to that many seconds.

Source

pub fn is_closed(&self) -> bool

Whether close has been called.

Source

pub async fn acquire(&self, timeout: Timeout) -> Result<T, PoolError>

Gets a connection, honoring cancellation (drop the future) and the acquire timeout.

Source

pub async fn release(&self, conn: T) -> Result<(), PoolError>

Returns a connection to the pool for reuse.

Source

pub async fn discard(&self, conn: T) -> Result<(), PoolError>

Returns a connection but forces it to be closed instead of reused.

Source

pub async fn release_with_error( &self, conn: T, error: &(dyn Error + 'static), ) -> Result<(), PoolError>

Returns a connection, signalling the caller’s work raised error.

Source

pub fn stats(&self) -> PoolStats

An immutable snapshot of pool counters and gauges.

Source

pub async fn run_maintenance(&self)

Performs one maintenance sweep (see ConnectionPool::run_maintenance).

Trait Implementations§

Source§

impl<T, F> Clone for AsyncConnectionPool<T, F>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<T, F> !RefUnwindSafe for AsyncConnectionPool<T, F>

§

impl<T, F> !UnwindSafe for AsyncConnectionPool<T, F>

§

impl<T, F> Freeze for AsyncConnectionPool<T, F>
where Arc<Inner<T, F>>: Freeze,

§

impl<T, F> Send for AsyncConnectionPool<T, F>
where Arc<Inner<T, F>>: Send,

§

impl<T, F> Sync for AsyncConnectionPool<T, F>
where Arc<Inner<T, F>>: Sync,

§

impl<T, F> Unpin for AsyncConnectionPool<T, F>
where Arc<Inner<T, F>>: Unpin,

§

impl<T, F> UnsafeUnpin for AsyncConnectionPool<T, F>
where Arc<Inner<T, F>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.