SharedUnboundedPool

Struct SharedUnboundedPool 

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

A threadsafe resource pool with a growable number of Resources.

Implementations§

Source§

impl<Resource, Reset> SharedUnboundedPool<Resource, Reset>

Source

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

Create a new SharedUnboundedPool, which initially has zero Resources.

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

§Potential Panics or Deadlocks

reset_resource must not call any method on the returned pool or any Clone or MirroredClone of it; otherwise, a panic or deadlock may occur.

Ideally, an reset_resource closure should not capture any SharedUnboundedPool.

Source§

impl<Resource> SharedUnboundedPool<Resource, ResetNothing>

Source

pub fn new_without_reset() -> Self

Create a new SharedUnboundedPool, which initially has zero Resources.

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

Source§

impl<Resource, Reset> SharedUnboundedPool<Resource, Reset>
where Resource: Default, Reset: ResetResource<Resource> + Clone,

Source

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

Get a Resource from the pool, returning a default Resource if none were already available in the pool.

Source§

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

Source

pub fn get<F>(&self, init_resource: F) -> PooledResource<Self, Resource>
where F: FnOnce() -> Resource,

Get a Resource from the pool.

§Potential Panics or Deadlocks

init_resource must not call any method on self or a Clone or MirroredClone associated with self; otherwise, a panic or deadlock may occur.

Ideally, an init_resource closure should not capture any SharedUnboundedPool.

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 SharedUnboundedPool<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 SharedUnboundedPool<Resource, Reset>

Source§

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

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

impl<Resource, Reset> Default for SharedUnboundedPool<Resource, Reset>
where Reset: ResetResource<Resource> + Clone + Default,

Source§

fn default() -> Self

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

impl<Resource, ResetResource, S> MirroredClone<S> for SharedUnboundedPool<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 SharedUnboundedPool<Resource, Reset>
where Reset: Freeze,

§

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

§

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

§

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

§

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

§

impl<Resource, Reset> !UnwindSafe for SharedUnboundedPool<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.