ForwardPool

Struct ForwardPool 

Source
pub struct ForwardPool { /* private fields */ }
Expand description

Forward Only Object Pool.

§Examples

use nuki::object_pool::*;

#[repr(C)]
#[derive(Debug, Default)]
struct ObjectFoo {
    base: PoolObjectBase,
    val: u64,
}

impl PoolObjectTypeId for ObjectFoo {
    fn pool_object_type_id(&self) -> usize {
        12345678
    }
}

impl ObjectFoo {
    fn base(&self) -> &PoolObjectBase {
        &self.base
    }

    fn base_mut(&mut self) -> &mut PoolObjectBase {
        &mut self.base
    }
}

let mut pool = ForwardPool::with_capacity(1024);
if let Some(foo) = pool.alloc::<ObjectFoo>(None) {
    assert_eq!(foo.base().pool_object_type(), 12345678);
    assert_eq!(
        foo.base().pool_object_size(),
        std::mem::size_of::<ObjectFoo>()
    );
}

Implementations§

Source§

impl ForwardPool

Source

pub fn with_capacity(capacity: usize) -> Self

Create the poll with capacity.

Source

pub unsafe fn as_ptr(&self) -> *const u8

Returns a raw pointer to the vector’s buffer.

§Safety
Source

pub unsafe fn as_mut_ptr(&mut self) -> *mut u8

Returns an unsafe mutable pointer to the vector’s buffer.

§Safety
Source

pub fn space(&self) -> usize

Return available bytes.

Source

pub fn used(&self) -> usize

Return used bytes.

Source

pub fn alloc<T: PoolObjectTypeId + Default>( &mut self, def_val: Option<T>, ) -> Option<&mut T>

Allocate an object and return the mutable reference.

Source

pub fn clear(&mut self)

Clear all objects in the pool.

Source

pub fn iter(&self) -> ForwardPoolIter<'_>

Returns an iterator over the objects.

Source

pub fn iter_mut(&mut self) -> ForwardPoolIterMut<'_>

Returns an iterator that allows modifying each object.

Trait Implementations§

Source§

impl Debug for ForwardPool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.