Trait opool::PoolAllocator

source ·
pub trait PoolAllocator<T> {
    // Required method
    fn allocate(&self) -> T;

    // Provided methods
    fn reset(&self, _obj: &mut T) { ... }
    fn is_valid(&self, _obj: &T) -> bool { ... }
}
Expand description

A trait defining the interface for a pool allocator.

This trait provides methods for resetting and creating new objects, as well as validating objects before they are stored back in the object pool.

Required Methods§

source

fn allocate(&self) -> T

Creates a new object of type T.

Provided Methods§

source

fn reset(&self, _obj: &mut T)

Resets the state of an object to its initial state if necessary.

By default, this method do nothing. Override this method to provide custom reset logic.

source

fn is_valid(&self, _obj: &T) -> bool

validates that an object is in a good state to be stored back in the object pool.

By default, this method always returns true. Override this method to provide custom validation logic.

Implementors§