Crate blind_pool

Crate blind_pool 

Source
Expand description

This package provides BlindPool, a dynamically growing pool of objects that can store objects of any type.

It offers automatic memory management with stable memory addresses and efficient typed insertion with automatic value dropping.

LocalBlindPool is a single-threaded variant with reduced overhead and RawBlindPool offers manual lifetime management for the most performance-sensitive scenarios.

§Features

  • Type-agnostic memory management: The pool accepts objects of any sized type.
  • Automatic resource management: Pooled objects are dropped automatically when no longer referenced.
  • Thread-safe and single-threaded variants: BlindPool for multi-threaded use, LocalBlindPool for single-threaded performance.
  • Always pinned: Memory address remains valid for the entire lifetime of a pooled object.
  • Dynamic growth: Pool capacity grows automatically as needed, shrinks to fit on-demand.
  • Efficient allocation: Uses high density slabs to minimize allocation overhead.
  • Stable Rust: No unstable Rust features required.
  • Optional leak detection: Pool can be configured to panic on drop if values are still present (primarily relevant for RawBlindPool).

§Example

use blind_pool::BlindPool;

// Create a thread-safe pool.
let pool = BlindPool::new();

// Insert values and get handles.
let u64_handle = pool.insert(42_u64);
let string_handle = pool.insert("hello".to_string());

// Access values through dereferencing.
assert_eq!(*u64_handle, 42);
assert_eq!(*string_handle, "hello");

// Values are automatically cleaned up when handles are dropped.

For single-threaded use:

use blind_pool::LocalBlindPool;

// Create a single-threaded pool (more efficient).
let pool = LocalBlindPool::new();

let value_handle = pool.insert(vec![1, 2, 3]);
assert_eq!(*value_handle, vec![1, 2, 3]);

For manual resource management:

use blind_pool::RawBlindPool;

// Create a pool with manual resource management.
let mut pool = RawBlindPool::new();

// Insert values of different types into the same pool.
let pooled_u64 = pool.insert(42_u64);
let pooled_i32 = pool.insert(-123_i32);
let pooled_f32 = pool.insert(3.14_f32);

// Read data back from the pooled items.
let value_u64 = *pooled_u64; // Safe deref access
let value_i32 = *pooled_i32; // Safe deref access

assert_eq!(value_u64, 42);
assert_eq!(value_i32, -123);

// Manual cleanup required.
unsafe { pool.remove(&pooled_u64) };
unsafe { pool.remove(&pooled_i32) };
unsafe { pool.remove(&pooled_f32) };

Macros§

define_pooled_dyn_cast
Defines a dynamic cast method that extends pooled item handles, allowing casting of the reference to a trait object.

Structs§

BlindPool
A thread-safe wrapper around RawBlindPool that provides automatic resource management and reference counting.
LocalBlindPool
A single-threaded wrapper around RawBlindPool that provides automatic resource management and reference counting.
LocalPooled
A reference to a value stored in a LocalBlindPool.
LocalPooledMut
A mutable reference to a value stored in a LocalBlindPool.
Pooled
A reference to a value stored in a BlindPool.
PooledMut
A mutable reference to a value stored in a BlindPool.
RawBlindPool
A pinned object pool of unbounded size that accepts objects of any type.
RawBlindPoolBuilder
Builder for creating an instance of RawBlindPool.
RawPooled
A handle representing an item stored in a RawBlindPool.
RawPooledMut
A handle to a value stored in a super::RawBlindPool with exclusive ownership guarantees.

Enums§

DropPolicy
Determines item dropping behavior when the container is dropped.