connpool

Crates.ioconnpool
lib.rsconnpool
version0.2.0
created_at2025-12-28 21:41:18.921706+00
updated_at2025-12-29 09:10:12.146526+00
descriptionA concurrent, generic connection pool for Rust
homepage
repositoryhttps://github.com/ferronweb/connpool
max_upload_size
id2009441
size31,497
Rust crate owners (github:ferronweb:rust-crate-owners)

documentation

https://docs.rs/connpool

README

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.

Commit count: 0

cargo fmt