Trait PoolStorage
pub trait PoolStorage:
Sized
+ Send
+ Sync
+ 'static {
type ConnID: PartialEq + Clone + Debug + Send + Sync + 'static;
type Connection: Send;
// Required methods
fn new(capacity: NonZero<u16>) -> Self;
fn add_connection(
&self,
conn: PooledConnection<Self::Connection, Self::ConnID>,
);
fn get_connection(
&self,
id: &Self::ConnID,
) -> Option<PooledConnection<Self::Connection, Self::ConnID>>;
fn get_connection_to_drop(
&self,
) -> Result<PooledConnection<Self::Connection, Self::ConnID>, OpaqueError>;
}
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 new(capacity: NonZero<u16>) -> Self
fn new(capacity: NonZero<u16>) -> Self
Initialize PoolStorage
with the given capacity. Implementer of this trait
can still decide if it will immedialty create storage of the given capacity,
or do it in a custom way (eg grow storage dynamically as needed)
fn add_connection(&self, conn: PooledConnection<Self::Connection, Self::ConnID>)
fn add_connection(&self, conn: PooledConnection<Self::Connection, Self::ConnID>)
Add connection to pool storage
fn get_connection(
&self,
id: &Self::ConnID,
) -> Option<PooledConnection<Self::Connection, Self::ConnID>>
fn get_connection( &self, id: &Self::ConnID, ) -> Option<PooledConnection<Self::Connection, Self::ConnID>>
Get a connection from this pool that is a match for the given Self::ConnID
.
Depending how connections are sorted and matched on ID, one can implement different
queue modes for connection reuse
fn get_connection_to_drop(
&self,
) -> Result<PooledConnection<Self::Connection, Self::ConnID>, OpaqueError>
fn get_connection_to_drop( &self, ) -> Result<PooledConnection<Self::Connection, Self::ConnID>, OpaqueError>
Get a connection from the pool with the intent to drop/replace it. This method will be used by the pool in case it is full and it wants to replace an old connection with a new one. By choosing which connection to return here one can implement different modes for connection dropping/replacing
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.