Expand description
This module contains the managed version of the pool. Managed meaning
that it requires a Manager
trait which is responsible for creating
and recycling objects as they are needed.
Example
use async_trait::async_trait;
#[derive(Debug)]
enum Error { Fail }
struct Computer {}
impl Computer {
async fn get_answer(&self) -> i32 {
42
}
}
struct Manager {}
#[async_trait]
impl deadpool::managed::Manager for Manager {
type Type = Computer;
type Error = Error;
async fn create(&self) -> Result<Computer, Error> {
Ok(Computer {})
}
async fn recycle(&self, conn: &mut Computer) -> deadpool::managed::RecycleResult<Error> {
Ok(())
}
}
type Pool = deadpool::managed::Pool<Manager>;
#[tokio::main]
async fn main() {
let mgr = Manager {};
let pool = Pool::new(mgr, 16);
let mut conn = pool.get().await.unwrap();
let answer = conn.get_answer().await;
assert_eq!(answer, 42);
}
For a more complete example please see
deadpool-postgres
Re-exports
pub use crate::Status;
Structs
A wrapper around the actual pooled object which implements the traits
Deref
, DerefMut
and Drop
. Use this object just as if it was of type
T
and upon leaving scope the drop
function will take care of
returning it to the pool.
A generic object and connection pool.
Pool configuration
Timeouts when getting objects from the pool
Enums
Error structure for Pool::get
This error is returned by the Manager::recycle
function
When Pool::get
returns a timeout error this enum can be used
to figure out which step caused the timeout.
Traits
This trait is used to create
new objects or recycle
existing ones.
Type Definitions
Result type for the recycle function