Skip to main content

PoolRegistry

Struct PoolRegistry 

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

Hands out one ConnectionPool per key, built on first use. It is lazy: a pool is created on first access and is NOT opened, so it does no background maintenance unless you open it yourself.

Implementations§

Source§

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

Source

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

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

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<ConnectionPool<T>, PoolError>

Returns the pool for key, creating it on first use. The returned pool is a cheap handle to the registry-owned pool.

Source

pub 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.

Source

pub fn close(&self)

Closes every pool and rejects further use.

Auto Trait Implementations§

§

impl<K, T> !Freeze for PoolRegistry<K, T>

§

impl<K, T> !RefUnwindSafe for PoolRegistry<K, T>

§

impl<K, T> !UnwindSafe for PoolRegistry<K, T>

§

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

§

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

§

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

§

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