pub struct ObjectPool<T> { /* private fields */ }Expand description
A simple object pool for reusing allocations.
This pool helps reduce allocation overhead when repeatedly creating and destroying objects of the same type during optimization loops.
§Example
use u_nesting_core::memory::ObjectPool;
let pool: ObjectPool<Vec<f64>> = ObjectPool::new(|| Vec::with_capacity(100));
// Get an object from the pool (or create new if empty)
let mut vec = pool.get();
vec.push(1.0);
vec.push(2.0);
// Return to pool for reuse (clears the vec)
pool.put(vec);
// Next get() will reuse the allocation
let vec2 = pool.get();
assert_eq!(vec2.capacity(), 100); // Capacity preservedImplementations§
Source§impl<T> ObjectPool<T>
impl<T> ObjectPool<T>
Sourcepub fn new<F>(factory: F) -> Selfwhere
F: Fn() -> T + 'static,
pub fn new<F>(factory: F) -> Selfwhere
F: Fn() -> T + 'static,
Creates a new object pool with the given factory function.
Sourcepub fn with_max_size<F>(factory: F, max_size: usize) -> Selfwhere
F: Fn() -> T + 'static,
pub fn with_max_size<F>(factory: F, max_size: usize) -> Selfwhere
F: Fn() -> T + 'static,
Creates a pool with a custom maximum size.
Auto Trait Implementations§
impl<T> !Freeze for ObjectPool<T>
impl<T> !RefUnwindSafe for ObjectPool<T>
impl<T> !Send for ObjectPool<T>
impl<T> !Sync for ObjectPool<T>
impl<T> Unpin for ObjectPool<T>where
T: Unpin,
impl<T> !UnwindSafe for ObjectPool<T>
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.