Expand description
Managed version of the pool.
“Managed” means that it requires a Manager which is responsible for
creating and recycling objects as they are needed.
§Example
use async_trait::async_trait;
use deadpool::managed;
#[derive(Debug)]
enum Error { Fail }
struct Computer {}
impl Computer {
    async fn get_answer(&self) -> i32 {
        42
    }
}
struct Manager {}
#[async_trait]
impl 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) -> managed::RecycleResult<Error> {
        Ok(())
    }
}
type Pool = managed::Pool<Manager>;
#[tokio::main]
async fn main() {
    let mgr = Manager {};
    let pool = Pool::builder(mgr).max_size(16).build().unwrap();
    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 crate.
Re-exports§
- pub use crate::Status;
Modules§
- This module contains all things that should be reexported by backend implementations in order to avoid direct dependencies on thedeadpoolcrate itself.
- syncDeprecatedHelpers for writing pools for objects that don’t support async and need to be run inside a thread.
Structs§
- Statistics regarding an object returned by the pool
- Generic object and connection pool.
- Builder forPools.
- Poolconfiguration.
Enums§
- Possible errors returned whenPoolBuilder::build()fails to build aPool.
- This error is used when building pools via the configcreate_poolmethods.
- Wrapper for hook functions
- Error structure which which can abort the creation and recycling of objects.
- Possible errors returned by hooks
- Possible errors returned byPool::get()method.
- Possible errors returned by theManager::recycle()method.
- Possible steps causing the timeout in an error returned byPool::get()method.
Traits§
- Manager responsible for creating newObjects or recycling existing ones.
Type Aliases§
- The boxed future that should be returned by async hooks
- The result returned by hooks
- Result type of theManager::recycle()method.