BoundedPool

Struct BoundedPool 

Source
pub struct BoundedPool<T> { /* private fields */ }
Expand description

Fixed-capacity object pool with LIFO reuse.

All objects are pre-initialized at construction. When all objects are acquired, try_acquire() returns None.

§Example

use nexus_pool::local::BoundedPool;

let pool = BoundedPool::new(
    100,
    || Vec::<u8>::with_capacity(1024),
    |v| v.clear(),
);

let mut buf = pool.try_acquire().unwrap();
buf.extend_from_slice(b"hello");
// buf auto-returns to pool on drop, clear() is called

Implementations§

Source§

impl<T> BoundedPool<T>

Source

pub fn new<I, R>(capacity: usize, init: I, reset: R) -> Self
where I: FnMut() -> T, R: FnMut(&mut T) + 'static,

Creates a pool with capacity pre-initialized objects.

§Arguments
  • capacity - Number of objects to pre-allocate
  • init - Factory function to create each object
  • reset - Called when object returns to pool (e.g., Vec::clear)
§Panics

Panics if capacity is zero.

Source

pub fn try_acquire(&self) -> Option<Pooled<T>>

Attempts to acquire an object from the pool.

Returns None if all objects are currently in use.

Source

pub fn available(&self) -> usize

Returns the number of available objects.

Source

pub fn is_empty(&self) -> bool

Returns true if there are no more available objects.

Auto Trait Implementations§

§

impl<T> Freeze for BoundedPool<T>

§

impl<T> !RefUnwindSafe for BoundedPool<T>

§

impl<T> !Send for BoundedPool<T>

§

impl<T> !Sync for BoundedPool<T>

§

impl<T> Unpin for BoundedPool<T>

§

impl<T> !UnwindSafe for BoundedPool<T>

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.