pub trait Allocator:
Send
+ Sync
+ 'static {
// Required method
fn allocate(&self, capacity: usize) -> Vec<u8> ⓘ;
}Expand description
Controls how the pool creates raw byte buffers.
§Contract
allocate(capacity)must return aVec<u8>withcapacity() >= capacity.- The returned
Vecmust havelen() == 0. - The
Vecmust 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);Required Methods§
Trait Implementations§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".