Poolable

Trait Poolable 

Source
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§

Source

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.

Source

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§

Source§

impl Poolable for bool

Source§

impl Poolable for char

Source§

impl Poolable for f32

Source§

impl Poolable for f64

Source§

impl Poolable for i8

Source§

impl Poolable for i16

Source§

impl Poolable for i32

Source§

impl Poolable for i64

Source§

impl Poolable for i128

Source§

impl Poolable for isize

Source§

impl Poolable for u8

Source§

impl Poolable for u16

Source§

impl Poolable for u32

Source§

impl Poolable for u64

Source§

impl Poolable for u128

Source§

impl Poolable for usize

Source§

impl Poolable for String

Available on crate feature std only.
Source§

impl<T: Poolable> Poolable for Option<T>

Source§

impl<T: Poolable> Poolable for [T; 1]

Source§

impl<T: Poolable> Poolable for [T; 2]

Source§

impl<T: Poolable> Poolable for [T; 3]

Source§

impl<T: Poolable> Poolable for [T; 4]

Source§

impl<T: Poolable> Poolable for [T; 8]

Source§

impl<T: Poolable> Poolable for [T; 16]

Source§

impl<T: Poolable> Poolable for [T; 32]

Source§

impl<T: Poolable> Poolable for [T; 64]

Source§

impl<T: Poolable> Poolable for [T; 128]

Source§

impl<T: Poolable> Poolable for [T; 256]

Source§

impl<T: Poolable> Poolable for Box<T>

Source§

impl<T: Poolable> Poolable for Vec<T>

Source§

impl<T: Poolable, E> Poolable for Result<T, E>

Source§

impl<T: Poolable, U: Poolable> Poolable for (T, U)

Source§

impl<T: Poolable, U: Poolable, V: Poolable> Poolable for (T, U, V)

Source§

impl<T: Poolable, U: Poolable, V: Poolable, W: Poolable> Poolable for (T, U, V, W)

Implementors§