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
impl ForwardPool
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create the poll with capacity.
Sourcepub unsafe fn as_mut_ptr(&mut self) -> *mut u8
pub unsafe fn as_mut_ptr(&mut self) -> *mut u8
Returns an unsafe mutable pointer to the vector’s buffer.
§Safety
Sourcepub fn alloc<T: PoolObjectTypeId + Default>(
&mut self,
def_val: Option<T>,
) -> Option<&mut T>
pub fn alloc<T: PoolObjectTypeId + Default>( &mut self, def_val: Option<T>, ) -> Option<&mut T>
Allocate an object and return the mutable reference.
Sourcepub fn iter(&self) -> ForwardPoolIter<'_> ⓘ
pub fn iter(&self) -> ForwardPoolIter<'_> ⓘ
Returns an iterator over the objects.
Sourcepub fn iter_mut(&mut self) -> ForwardPoolIterMut<'_> ⓘ
pub fn iter_mut(&mut self) -> ForwardPoolIterMut<'_> ⓘ
Returns an iterator that allows modifying each object.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ForwardPool
impl RefUnwindSafe for ForwardPool
impl Send for ForwardPool
impl Sync for ForwardPool
impl Unpin for ForwardPool
impl UnwindSafe for ForwardPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more