Deadpool is a dead simple async pool for connections and objects of any type.
This crate implements a deadpool
manager for r2d2
managers.
| Feature | Description | Extra dependencies | Default |
| ------- | ----------- | ------------------ | ------- |
| rt_tokio_1
| Enable support for tokio crate | deadpool/rt_tokio_1
| yes |
| rt_async-std_1
| Enable support for async-std crate | deadpool/rt_async-std_1
| no |
| serde
| Enable support for serde crate | deadpool/serde
| no |
```rust use std::env;
use deadpool_r2d2::Runtime;
type PostgresManager = deadpoolr2d2::Manager<
r2d2postgres::PostgresConnectionManager
; type PostgresPool = deadpool_r2d2::Pool
;
fn createpool(maxsize: usize) -> PostgresPool { let mut pgconfig = r2d2postgres::postgres::Config::new(); pgconfig.hostpath("/run/postgresql"); pgconfig.user(&env::var("USER").unwrap()); pgconfig.dbname("deadpool"); let r2d2manager = r2d2postgres::PostgresConnectionManager::new(pgconfig, r2d2postgres::postgres::NoTls); let manager = PostgresManager::new(r2d2manager, Runtime::Tokio1); let pool = PostgresPool::builder(manager) .maxsize(max_size) .build() .unwrap(); pool }
async fn main() { let pool = createpool(2); let client = pool.get().await.unwrap(); let answer: i32 = client .interact(|client| { let row = client.queryone("SELECT 42", &[])?; Ok(row.get(0)) }) .await .unwrap(); assert_eq!(answer, 42); } ```
Licensed under either of
at your option.