infinity_pool

Crates.ioinfinity_pool
lib.rsinfinity_pool
version0.7.2
created_at2025-09-07 11:13:42.216108+00
updated_at2025-09-22 14:55:01.594537+00
descriptionOffers object pooling capabilities both thread-safe and single threaded, both lifetime-managed and manual, both typed and untyped
homepage
repositoryhttps://github.com/folo-rs/folo
max_upload_size
id1828036
size736,515
Sander Saares (sandersaares)

documentation

README

Infinity Pool

Object pools with trait object support and multiple access models. Provides faster alternatives to Box::pin(), Arc::pin() and Rc::pin().

Pool types

  • PinnedPool - basic object pool for a single type with pinned memory guarantees
  • OpaquePool - for objects with unnameable types (e.g. impl Future)
  • BlindPool - accepts multiple different types in the same pool

All pools support trait object casting.

Access models

Each pool type comes in three variants:

  • Thread-safe with Arc-style handles (default)
  • Single-threaded with Rc-style handles (Local* variants)
  • Manual lifetime management (Raw* variants)

Example

use std::fmt::Display;
use infinity_pool::{BlindPool, PinnedPool, define_pooled_dyn_cast};

// Enable casting to Display trait objects
define_pooled_dyn_cast!(Display);

fn main() {
    // PinnedPool: thread-safe pool for a single type
    let mut pinned_pool = PinnedPool::<String>::new();
    let handle = pinned_pool.insert("Hello, PinnedPool!".to_string());
    
    // Cast PinnedPool handle to trait object and pass to function
    let display_pinned = handle.cast_display();
    print_item("PinnedPool", &display_pinned);
    
    // BlindPool: thread-safe pool for multiple types
    let mut blind_pool = BlindPool::new();
    let string_handle = blind_pool.insert("Hello, BlindPool!".to_string());
    let number_handle = blind_pool.insert(42_i32);
    
    // Cast to trait objects and pass to function that accepts AsRef<dyn Display>
    let display_string = string_handle.cast_display();
    let display_number = number_handle.cast_display();
    
    print_item("BlindPool string", &display_string);
    print_item("BlindPool number", &display_number);
}

/// Function that accepts anything that can be borrowed as a Display trait object
fn print_item(label: &str, item: &impl AsRef<dyn Display>) {
    println!("{}: {}", label, item.as_ref());
}

More details in the package documentation.

This is part of the Folo project that provides mechanisms for high-performance hardware-aware programming in Rust.

Commit count: 810

cargo fmt