Trait Pool

pub trait Pool<C, ID>:
    Send
    + Sync
    + 'static {
    type Connection: Send;
    type CreatePermit: Send;

    // Required methods
    fn get_conn(
        &self,
        id: &ID,
    ) -> impl Future<Output = Result<ConnectionResult<Self::Connection, Self::CreatePermit>, OpaqueError>> + Send;
    fn create(
        &self,
        id: ID,
        conn: C,
        create_permit: Self::CreatePermit,
    ) -> impl Future<Output = Self::Connection> + Send;
}
Expand description

[PoolStorage] implements the storage part of a connection pool. This storage also decides which connection it returns for a given ID or when the caller asks to remove one, this results in the storage deciding which mode we use for connection reuse and dropping (eg FIFO for reuse and LRU for dropping conn when pool is full)

Required Associated Types§

Required Methods§

fn get_conn( &self, id: &ID, ) -> impl Future<Output = Result<ConnectionResult<Self::Connection, Self::CreatePermit>, OpaqueError>> + Send

Get a connection from the pool, if no connection is found a Pool::CreatePermit is returned

A Pool::CreatePermit is needed to add a new connection to the pool. Depending on how the Pool::CreatePermit is used a pool can implement policies for max connection and max total connections.

fn create( &self, id: ID, conn: C, create_permit: Self::CreatePermit, ) -> impl Future<Output = Self::Connection> + Send

Create/add a new connection to the pool

To be able to a connection to the pool you need a Pool::CreatePermit, depending on how the pool implements this you might need to call Pool::get_conn to get this first.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

§

impl<C, ID> Pool<C, ID> for FiFoReuseLruDropPool<C, ID>
where C: Send + 'static, ID: Clone + Send + Sync + PartialEq + Debug + 'static,

§

impl<C, ID> Pool<C, ID> for NoPool
where C: Send + 'static, ID: Clone + Send + Sync + PartialEq + 'static,