Pool

Struct Pool 

Source
pub struct Pool<T: Send> { /* private fields */ }
Expand description

A pool of objects. After an object is taken from the pool, it is returned to the pool when it is dropped. Pool items must be passed on creation by values:

§Examples

basic usage:

let pool = autoreturn_pool::Pool::new([1, 2]);
let item = pool.take();

with custom config:

let config = autoreturn_pool::Config {
   wait_duration: std::time::Duration::from_millis(5),
};
let pool = autoreturn_pool::Pool::with_config(config, [1, 2]);
let item = pool.take();

Implementations§

Source§

impl<T: Send + 'static> Pool<T>

Source

pub fn new(items: impl IntoIterator<Item = T>) -> Self

Source

pub fn with_config(config: Config, items: impl IntoIterator<Item = T>) -> Self

Source

pub fn take(&self) -> Option<PoolObject<'_, T>>

Take an object from the pool. If the pool is empty, the method will wait for the object to be returned to the pool. If the wait duration is exceeded, the method will return None.

Source

pub fn add(&self, item: T)

Allows to add new object to the pool.

Source

pub fn size(&self) -> usize

Get the number of available objects in the pool.

Auto Trait Implementations§

§

impl<T> !Freeze for Pool<T>

§

impl<T> !RefUnwindSafe for Pool<T>

§

impl<T> Send for Pool<T>

§

impl<T> Sync for Pool<T>

§

impl<T> Unpin for Pool<T>
where T: Unpin,

§

impl<T> UnwindSafe for Pool<T>
where T: UnwindSafe,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.