1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! Pluggable buffer allocation backend.
//!
//! [`ZeroPool`](crate::ZeroPool) delegates raw buffer creation to an [`Allocator`].
//! The default [`HeapAllocator`] uses `Vec::with_capacity` (standard heap).
//! Implement the trait for custom strategies (page-aligned, huge pages, etc.).
/// Controls how the pool creates raw byte buffers.
///
/// # Contract
///
/// - `allocate(capacity)` must return a `Vec<u8>` with `capacity() >= capacity`.
/// - The returned `Vec` must have `len() == 0`.
/// - The `Vec` must be deallocatable by the standard global allocator.
///
/// # Example
///
/// ```
/// use zeropool::{Allocator, ZeroPool};
///
/// struct PrefaultAllocator;
///
/// impl Allocator for PrefaultAllocator {
/// fn allocate(&self, capacity: usize) -> Vec<u8> {
/// let mut buf = Vec::with_capacity(capacity);
/// buf.resize(capacity, 0); // pre-fault pages
/// buf.clear();
/// buf
/// }
/// }
///
/// let pool = ZeroPool::new().allocator(PrefaultAllocator);
/// ```
/// Standard heap allocation via `Vec::with_capacity`.
///
/// This is the default — zero-sized, no overhead.
;