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
//! Pluggable buffer allocation backend.
//!
//! [`ZeroPool`](crate::ZeroPool) delegates raw buffer creation to an [`Allocator`].
//! The default [`HeapAllocator`] returns zero-initialized heap buffers.
//! 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 `len() >= capacity`.
/// - The first `capacity` bytes must be initialized to zero.
/// - The returned `Vec` must have `capacity() >= len()`.
/// - 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> {
/// vec![0; capacity]
/// }
/// }
///
/// let pool = ZeroPool::new().allocator(PrefaultAllocator);
/// ```
/// Standard heap allocation via `vec![0; capacity]`.
///
/// This is the default safe allocator used by [`ZeroPool`](crate::ZeroPool).
;