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.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
impl Poolable for String
Available on crate feature
std only.