Skip to main content

AsyncPoolRegistry

Struct AsyncPoolRegistry 

Source
pub struct AsyncPoolRegistry<K, T, F> { /* private fields */ }
Expand description

Hands out one AsyncConnectionPool per key, built on first use. Lazy: pools are not opened automatically.

Implementations§

Source§

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

Source

pub fn new<Fun>(factory_for: Fun, config: PoolConfig) -> Self
where Fun: Fn(&K) -> F + Send + Sync + 'static,

Builds a registry. factory_for makes the factory for a given key; config is shared.

Source

pub fn with_clock(self, clock: Arc<dyn Clock>) -> Self

Shares clock with every pool the registry creates.

Source

pub fn with_listeners(self, listeners: Vec<Arc<dyn PoolListener<T>>>) -> Self

Shares listeners with every pool the registry creates.

Source

pub fn pool(&self, key: &K) -> Result<AsyncConnectionPool<T, F>, PoolError>

Returns the pool for key, creating it on first use.

Source

pub async fn close(&self)

Closes every pool and rejects further use.

Source

pub async fn with_connection<R>( &self, key: &K, timeout: Timeout, f: impl FnOnce(&T) -> R, ) -> Result<R, PoolError>

Borrows a connection from the pool for key for the duration of f.

Auto Trait Implementations§

§

impl<K, T, F> !Freeze for AsyncPoolRegistry<K, T, F>

§

impl<K, T, F> !RefUnwindSafe for AsyncPoolRegistry<K, T, F>

§

impl<K, T, F> !UnwindSafe for AsyncPoolRegistry<K, T, F>

§

impl<K, T, F> Send for AsyncPoolRegistry<K, T, F>
where Box<dyn Fn(&K) -> F + Send + Sync>: Send, Vec<Arc<dyn PoolListener<T>>>: Send, Mutex<RegState<K, T, F>>: Send,

§

impl<K, T, F> Sync for AsyncPoolRegistry<K, T, F>
where Box<dyn Fn(&K) -> F + Send + Sync>: Sync, Vec<Arc<dyn PoolListener<T>>>: Sync, Mutex<RegState<K, T, F>>: Sync,

§

impl<K, T, F> Unpin for AsyncPoolRegistry<K, T, F>
where Box<dyn Fn(&K) -> F + Send + Sync>: Unpin, Vec<Arc<dyn PoolListener<T>>>: Unpin, Mutex<RegState<K, T, F>>: Unpin,

§

impl<K, T, F> UnsafeUnpin for AsyncPoolRegistry<K, T, F>
where Box<dyn Fn(&K) -> F + Send + Sync>: UnsafeUnpin, Vec<Arc<dyn PoolListener<T>>>: UnsafeUnpin, Mutex<RegState<K, 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> 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, 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.