pub trait Poolable {
// Provided methods
fn on_acquire(&mut self) { ... }
fn on_release(&mut self) { ... }
}Expand description
A trait for types that can be used with memory pools.
This trait provides hooks for custom initialization and cleanup logic when objects are allocated from or returned to a pool.
§Examples
use fastalloc::Poolable;
struct GameEntity {
position: (f32, f32),
velocity: (f32, f32),
health: i32,
}
impl Poolable for GameEntity {
fn on_acquire(&mut self) {
// Reset state when acquired from pool
self.position = (0.0, 0.0);
self.velocity = (0.0, 0.0);
self.health = 100;
}
fn on_release(&mut self) {
// Cleanup before returning to pool
// (optional - could clear resources, etc.)
}
}Provided Methods§
Sourcefn on_acquire(&mut self)
fn on_acquire(&mut self)
Called when an object is acquired from the pool.
This is a good place to reset the object to a clean state. The default implementation does nothing.
Sourcefn on_release(&mut self)
fn on_release(&mut self)
Called when an object is being returned to the pool.
This is a good place to perform cleanup or release resources. The default implementation does nothing.
Implementations on Foreign Types§
impl Poolable for bool
impl Poolable for char
impl Poolable for f32
impl Poolable for f64
impl Poolable for i8
impl Poolable for i16
impl Poolable for i32
impl Poolable for i64
impl Poolable for i128
impl Poolable for isize
impl Poolable for u8
impl Poolable for u16
impl Poolable for u32
impl Poolable for u64
impl Poolable for u128
impl Poolable for usize
impl Poolable for String
Available on crate feature
std only.