Pool

Struct Pool 

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

The pseudo-pool container. This holds the inventory of objects that can be checked in/out & automatically tracks when checked out objects are out of scope to return them to the pool. The objects can carry payloads (which must all be of the same type).

Implementations§

Source§

impl<T> Pool<T>

Source

pub fn new() -> Self

Create a new, empty pool.

Source

pub fn new_from_iterable<V: IntoIterator<Item = T>>(vec: V) -> Self

Create a new pool with initial contents from an iterable of object payloads.

Source

pub fn add_entry(&mut self, payload: T)

Add an object, with a specific payload, to the pool.

Source

pub fn extend_entries<V: IntoIterator<Item = T>>(&mut self, vec: V)

Add objects to the pool from an iterable of payloads.

Source

pub fn checkout_blocking(&mut self) -> Result<ExternalPoolEntry<T>>

Get an object from the pool, if available, or block until an object is available. Returns the object. (This is the entire reason this crate exists.)

Source

pub fn try_checkout(&mut self) -> Option<ExternalPoolEntry<T>>

Get an object from the pool, wrapped in an Option, if available, or None if there are no such objects currently.

Source

pub fn update_leases(&mut self) -> usize

Update the available objects with recently returned objects. Returns the count of available objects.

Source

pub fn leases(&self) -> usize

Get the number of available objects in the pool. May be inaccurate (lower than the actual number) if objects have been returned, but no checkout or update_leases have occurred.

Trait Implementations§

Source§

impl<T> Default for Pool<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Pool<T>

§

impl<T> RefUnwindSafe for Pool<T>

§

impl<T> Send for Pool<T>
where T: Send + Sync,

§

impl<T> Sync for Pool<T>
where T: Send + Sync,

§

impl<T> Unpin for Pool<T>

§

impl<T> UnwindSafe for Pool<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.