Skip to main content

VecPool

Struct VecPool 

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

A simple frame pool backed by a Vec of reusable buffers.

Stores up to capacity buffers and returns them to callers via FramePool::acquire. When exhausted, acquire returns None and the caller allocates a new buffer directly.

§Thread Safety

All access is protected by a Mutex, making VecPool safe to share across threads via Arc<VecPool>.

§Examples

use ff_common::VecPool;

let pool = VecPool::new(32);
assert_eq!(pool.available(), 0); // pool starts empty

Implementations§

Source§

impl VecPool

Source

pub fn new(capacity: usize) -> Arc<Self>

Creates a new pool with the given maximum buffer count.

§Arguments
  • capacity - Maximum number of buffers to retain in the pool.
Source

pub fn capacity(&self) -> usize

Returns the maximum number of buffers this pool will retain.

Source

pub fn available(&self) -> usize

Returns the number of buffers currently available in the pool.

§Examples
use ff_common::VecPool;

let pool = VecPool::new(8);
assert_eq!(pool.available(), 0);

Trait Implementations§

Source§

impl Debug for VecPool

Source§

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

Formats the value using the given formatter. Read more
Source§

impl FramePool for VecPool

Source§

fn acquire(&self, size: usize) -> Option<PooledBuffer>

Acquires a buffer of at least the specified size from the pool. Read more
Source§

fn release(&self, buffer: Vec<u8>)

Returns a buffer to the pool. 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.