Trait Pool
pub trait Pool<C, ID>:
Send
+ Sync
+ 'static {
type Connection: Send + ExtensionsRef;
type CreatePermit: Send;
// Required methods
fn get_conn(
&self,
id: &ID,
input: &Extensions,
deadline: Option<Instant>,
) -> impl Future<Output = Result<ConnectionResult<Self::Connection, Self::CreatePermit>, Box<dyn Error + Sync + Send>>> + Send;
fn abandon(
&self,
create_permit: Self::CreatePermit,
error: &ConnectionError,
);
fn create(
&self,
id: ID,
conn: C,
create_permit: Self::CreatePermit,
input: &Extensions,
) -> impl Future<Output = Result<Self::Connection, Box<dyn Error + Sync + Send>>> + Send;
}net only.Expand description
Pool 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§
type Connection: Send + ExtensionsRef
type CreatePermit: Send
Required Methods§
fn get_conn(
&self,
id: &ID,
input: &Extensions,
deadline: Option<Instant>,
) -> impl Future<Output = Result<ConnectionResult<Self::Connection, Self::CreatePermit>, Box<dyn Error + Sync + Send>>> + Send
fn get_conn( &self, id: &ID, input: &Extensions, deadline: Option<Instant>, ) -> impl Future<Output = Result<ConnectionResult<Self::Connection, Self::CreatePermit>, Box<dyn Error + Sync + Send>>> + Send
Get a compatible connection, or a permit to establish a new connection.
Implementations read a connection’s ConnectionReuse once, in
create, and only hand it to requests whose key matches its key.
Pools which retain connections must honor ConnectionAdmission before
handout and hold its lease until consumed or dropped. Evaluate providers
and compatibility policies outside storage and admission locks.
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.
deadline is when the caller stops waiting, if it does: a pool that lets
a checkout wait for another’s connect has it dial its own by then.
fn abandon(&self, create_permit: Self::CreatePermit, error: &ConnectionError)
fn abandon(&self, create_permit: Self::CreatePermit, error: &ConnectionError)
The connection create_permit was for could not be established. Pools
that let checkouts wait for it instead of dialing fail them alike.
fn create(
&self,
id: ID,
conn: C,
create_permit: Self::CreatePermit,
input: &Extensions,
) -> impl Future<Output = Result<Self::Connection, Box<dyn Error + Sync + Send>>> + Send
fn create( &self, id: ID, conn: C, create_permit: Self::CreatePermit, input: &Extensions, ) -> impl Future<Output = Result<Self::Connection, Box<dyn Error + Sync + Send>>> + Send
Admit the establishing request before publishing its new connection.
Retaining pools reserve any ConnectionAdmission resources against
input before exposing the connection to concurrent checkouts. Obtain
the creation permit from Self::get_conn.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".