Expand description
A generic connection pool.
Implementors of the ManageConnection
trait provide the specific
logic to create and check the health of connections.
§Example
ⓘ
use std::io;
use std::net::SocketAddr;
use async_trait::async_trait;
use mpool::{ManageConnection, Pool};
use tokio::net::TcpStream;
struct MyPool {
addr: SocketAddr,
}
#[async_trait]
impl ManageConnection for MyPool {
type Connection = TcpStream;
async fn connect(&self) -> io::Result<Self::Connection> {
TcpStream::connect(self.addr).await
}
async fn check(&self, _conn: &mut Self::Connection) -> io::Result<()> {
Ok(())
}
}
Structs§
- Builder
- A builder for a connection pool.
- Connection
- A smart pointer wrapping a connection.
- Pool
- A generic connection pool.
Traits§
- Manage
Connection - A trait which provides connection-specific functionality.