santh_bufpool/lib.rs
1//! Typed buffer recycling with fixed size classes and lock-free queues.
2//!
3//! The pool keeps four reusable buffer classes: 4 KiB, 64 KiB, 256 KiB, and
4//! 1 MiB. Requests are rounded up to the smallest fitting class. If a class is
5//! exhausted, the pool falls back to a one-off allocation without blocking.
6//!
7//! # Examples
8//!
9//! ```rust
10//! use santh_bufpool::{BufferPool, PoolConfig};
11//!
12//! let pool = BufferPool::new(PoolConfig {
13//! four_kib_count: 2,
14//! ..PoolConfig::default()
15//! });
16//! let mut buffer = pool.checkout(128).unwrap();
17//! buffer[0] = 42;
18//! assert_eq!(buffer.len(), 128);
19//! assert!(buffer.capacity() >= 128);
20//! ```
21
22#![warn(missing_docs, clippy::pedantic)]
23#![cfg_attr(
24 not(test),
25 deny(
26 clippy::unwrap_used,
27 clippy::expect_used,
28 clippy::todo,
29 clippy::unimplemented,
30 clippy::panic
31 )
32)]
33#![allow(clippy::module_name_repetitions, clippy::must_use_candidate)]
34
35mod buffer;
36mod config;
37/// Error types and constants for bufpool.
38pub mod error;
39mod pool;
40mod size_class;
41mod stats;
42mod tls;
43
44pub use buffer::{FrozenBuffer, PoolBuffer};
45pub use config::PoolConfig;
46pub use error::{Error, Result};
47pub use pool::BufferPool;
48pub use stats::{PoolStats, PoolStatsSnapshot};
49
50#[doc(hidden)]
51pub use tls::clear_tls_cache as clear_tls_cache_for_test;