3 unstable releases

0.2.0 Dec 29, 2025
0.1.1 Dec 29, 2025
0.1.0 Dec 28, 2025

#762 in Asynchronous

Download history 56/week @ 2025-12-27 381/week @ 2026-01-03 411/week @ 2026-01-10 385/week @ 2026-01-17 150/week @ 2026-01-24 226/week @ 2026-01-31 950/week @ 2026-02-07 341/week @ 2026-02-14 211/week @ 2026-02-21

1,777 downloads per month

MIT license

22KB
422 lines

connpool - a concurrent, generic connection pool for Rust

connpool is a high-performance, generic connection pool crate designed for Rust applications. It provides a thread-safe, asynchronous pool for managing and reusing connections (or any other resource) with both global and local (per-key) limits.

Features

  • Concurrent access - uses Arc and RwLock for thread-safe operations.
  • Global and local limits - enforce both global pool limits and per-key local limits using semaphores.
  • Asynchronous - supports async Rust.
  • Automatic eviction - automatically evicts items when the pool is full.
  • Flexible key/value types - works with any key/value types that implement Eq + Hash.
  • Unbounded mode - option to create a pool without a global limit.

Usage

use connpool::Pool;

#[tokio::main]
async fn main() {
    // Create a new pool with a global limit of 10 connections
    let pool = Pool::new(10);

    // Pull a connection for a specific key
    let item = pool.pull("my_key").await;

    // Use the connection
    if let Some(value) = item.inner() {
        let value: usize = *value;
        println!("Got value: {:?}", value);
    }

    // The connection is automatically returned to the pool when `item` is dropped
    // Alternatively, drop the connection
    let _ = item.take();
}

Advanced usage

  • Local limits - set per-key limits to restrict the number of concurrent connections for specific keys.
  • Manual management - use pull_with_local_limit for fine-grained control over local limits.

License

This project is licensed under the MIT License.

Dependencies

~3.5–4.5MB
~70K SLoC