SharedBoundedPool

Struct SharedBoundedPool 

Source
pub struct SharedBoundedPool<Resource, Reset> { /* private fields */ }
Expand description

A threadsafe resource pool with a fixed number of Resources.

Implementations§

Source§

impl<Resource, Reset> SharedBoundedPool<Resource, Reset>

Source

pub fn new<F>(pool_size: usize, init_resource: F, reset_resource: Reset) -> Self
where F: FnMut() -> Resource, Reset: ResetResource<Resource> + Clone,

Create a new SharedBoundedPool which has the indicated, fixed number of Resources.

Each Resource is immediately initialized, using the provided function.

Whenever a Resource is returned to the pool, reset_resource is run on it first.

Source§

impl<Resource: Default, Reset> SharedBoundedPool<Resource, Reset>

Source

pub fn new_default(pool_size: usize, reset_resource: Reset) -> Self
where Reset: ResetResource<Resource> + Clone,

Create a new SharedBoundedPool which has the indicated, fixed number of Resources.

Each Resource is immediately initialized to its default value.

Whenever a Resource is returned to the pool, reset_resource is run on it first.

Source§

impl<Resource> SharedBoundedPool<Resource, ResetNothing>

Source

pub fn new_without_reset<F>(pool_size: usize, init_resource: F) -> Self
where F: FnMut() -> Resource,

Create a new SharedBoundedPool which has the indicated, fixed number of Resources.

Each Resource is immediately initialized, using the provided function.

When a Resource is returned to the pool, it is not reset in any way.

Source§

impl<Resource: Default> SharedBoundedPool<Resource, ResetNothing>

Source

pub fn new_default_without_reset(pool_size: usize) -> Self

Create a new SharedBoundedPool which has the indicated, fixed number of Resources.

Each Resource is immediately initialized to its default value.

When a Resource is returned to the pool, it is not reset in any way.

Source§

impl<Resource, Reset: ResetResource<Resource> + Clone> SharedBoundedPool<Resource, Reset>

Source

pub fn try_get( &self, ) -> Result<PooledResource<Self, Resource>, ResourcePoolEmpty>

Get a Resource from the pool, if any are available.

Source

pub fn get(&self) -> PooledResource<Self, Resource>

Get a Resource from the pool.

May need to wait for a resource to become available.

§Potential Panics or Deadlocks

If self.pool_size() == 0, then this method will panic or deadlock. This method may also cause a deadlock if no Resources are currently available, and the current thread needs to make progress in order to release a Resource.

Source

pub fn pool_size(&self) -> usize

Get the total number of Resources in this pool, whether available or in-use.

Source

pub fn available_resources(&self) -> usize

Get the number of Resources in the pool which are not currently being used.

Trait Implementations§

Source§

impl<Resource, ResetResource: Clone> Clone for SharedBoundedPool<Resource, ResetResource>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Resource: Debug, Reset: Debug> Debug for SharedBoundedPool<Resource, Reset>

Source§

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

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

impl<Resource, ResetResource, S> MirroredClone<S> for SharedBoundedPool<Resource, ResetResource>
where ResetResource: MirroredClone<S>, S: Speed,

Available on crate feature clone-behavior only.
Source§

fn mirrored_clone(&self) -> Self

Get a clone that shares all semantically-important mutable state with its source. Read more
Source§

fn fast_mirrored_clone(&self) -> Self
where S: FastSpeed,

Get a clone that shares all semantically-important mutable state with its source. Read more

Auto Trait Implementations§

§

impl<Resource, Reset> Freeze for SharedBoundedPool<Resource, Reset>
where Reset: Freeze,

§

impl<Resource, Reset> !RefUnwindSafe for SharedBoundedPool<Resource, Reset>

§

impl<Resource, Reset> Send for SharedBoundedPool<Resource, Reset>
where Reset: Send, Resource: Send,

§

impl<Resource, Reset> Sync for SharedBoundedPool<Resource, Reset>
where Reset: Sync, Resource: Send,

§

impl<Resource, Reset> Unpin for SharedBoundedPool<Resource, Reset>
where Reset: Unpin,

§

impl<Resource, Reset> !UnwindSafe for SharedBoundedPool<Resource, Reset>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.