Available on crate feature
managed
only.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 deadpool::managed;
#[derive(Debug)]
enum Error { Fail }
struct Computer {}
impl Computer {
async fn get_answer(&self) -> i32 {
42
}
}
struct Manager {}
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::Metrics) -> 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§
- reexports
- This module contains all things that should be reexported
by backend implementations in order to avoid direct dependencies
on the
deadpool
crate itself.
Structs§
- Metrics
- Statistics regarding an object returned by the pool
- Object
- Wrapper around the actual pooled object which implements
Deref
,DerefMut
andDrop
traits. - Pool
- Generic object and connection pool.
- Pool
Builder - Builder for
Pool
s. - Pool
Config Pool
configuration.- Retain
Result - This is the result returned by
Pool::retain
- Timeouts
- Timeouts when getting
Object
s from aPool
.
Enums§
- Build
Error - Possible errors returned when
PoolBuilder::build()
fails to build aPool
. - Create
Pool Error - This error is used when building pools via the config
create_pool
methods. - Hook
- Wrapper for hook functions
- Hook
Error - Error which is returned by
pre_create
,pre_recycle
andpost_recycle
hooks. - Pool
Error - Possible errors returned by
Pool::get()
method. - Queue
Mode - Mode for dequeuing
Object
s from aPool
. - Recycle
Error - Possible errors returned by the
Manager::recycle()
method. - Timeout
Type - Possible steps causing the timeout in an error returned by
Pool::get()
method.
Traits§
Type Aliases§
- Hook
Future - The boxed future that should be returned by async hooks
- Hook
Result - The result returned by hooks
- Recycle
Result - Result type of the
Manager::recycle()
method.