pub struct InitPool<T: Send + Sync + 'static, I: Init> { /* private fields */ }
Expand description
A pool of objects of type T
that can be leased out. Just like a Pool
, but
it also carries an initializer that ensures each item is consistently initialized
Implementations§
source§impl<T: Send + Sync + 'static, I: Init> InitPool<T, I>
impl<T: Send + Sync + 'static, I: Init> InitPool<T, I>
sourcepub fn try_into_locked_pool(
self
) -> Result<LockedPool<T>, (Pool<T>, PoolConversionError)>
pub fn try_into_locked_pool( self ) -> Result<LockedPool<T>, (Pool<T>, PoolConversionError)>
Turns this Pool
into a LockedPool
§Errors
Will return an error if any of the variants in PoolConversionError
apply
sourcepub fn new_from<O: Into<I>>(init: O) -> Self
pub fn new_from<O: Into<I>>(init: O) -> Self
Creates a new empty Pool
that will be initialized using init
sourcepub fn init(&self) -> I::Output
pub fn init(&self) -> I::Output
Returns the output of the initializer so that consumers can get an initialized value that isn’t tied to the pool
sourcepub async fn get(&self) -> Lease<T>
pub async fn get(&self) -> Lease<T>
Returns a future that resolves to a Lease
when one is available
Reqires the async
feature to be enabled because it requires extra memory
sourcepub fn try_get_or_new(&self) -> Lease<T>
pub fn try_get_or_new(&self) -> Lease<T>
For the asynchronous version of this function see get_or_new()
Tries to get an existing Lease
if available and if not returns a new one that has been added to the pool.
Calling this method repeatedly can cause the pool size to increase without bound.
sourcepub async fn get_or_new(&self) -> Lease<T>
pub async fn get_or_new(&self) -> Lease<T>
Asynchronous version of try_get_or_new()
Tries to get an existing Lease
if available and if not returns a new one that has been added to the pool.
Calling this method repeatedly can cause the pool size to increase without bound.
sourcepub fn try_get_or_try_new<E>(&self) -> Result<Lease<T>, E>
pub fn try_get_or_try_new<E>(&self) -> Result<Lease<T>, E>
For the asynchronous version of this function see get_or_try_new()
Tries to get an existing Lease
if available and if not tries to create a new one that has been added to the pool.
Calling this method repeatedly can cause the pool size to increase without bound.
§Errors
Returns an error if the stored initializer errors
sourcepub async fn get_or_try_new<E>(&self) -> Result<Lease<T>, E>
pub async fn get_or_try_new<E>(&self) -> Result<Lease<T>, E>
Asynchronous version of try_get_or_try_new()
Tries to get an existing Lease
if available and if not tries to create a new one that has been added to the pool.
Calling this method repeatedly can cause the pool size to increase without bound.
§Errors
Returns an error if the stored initializer errors
sourcepub fn try_get_or_new_with_cap(&self, cap: usize) -> Option<Lease<T>>
pub fn try_get_or_new_with_cap(&self, cap: usize) -> Option<Lease<T>>
For the asynchronous version of this function see get_or_new_with_cap()
Just like get_or_new()
but caps the size of the pool. Once len()
== cap
then None
is returned.
sourcepub async fn get_or_new_with_cap(&self, cap: usize) -> Lease<T>
pub async fn get_or_new_with_cap(&self, cap: usize) -> Lease<T>
Asynchronous version of get_or_new_with_cap()
Just like get_or_new()
but caps the size of the pool. Once len()
== cap
then it waits for an open lease.
sourcepub fn try_get_or_try_new_with_cap<E>(
&self,
cap: usize
) -> Result<Option<Lease<T>>, E>
pub fn try_get_or_try_new_with_cap<E>( &self, cap: usize ) -> Result<Option<Lease<T>>, E>
For the asynchronous version of this function see get_or_try_new_with_cap()
Just like get_or_try_new()
but caps the size of the pool. Once len()
== cap
then None
is returned.
§Errors
Returns an error if the stored initializer errors
sourcepub async fn get_or_try_new_with_cap<E>(
&self,
cap: usize
) -> Result<Lease<T>, E>
pub async fn get_or_try_new_with_cap<E>( &self, cap: usize ) -> Result<Lease<T>, E>
Asynchronous version of get_or_try_new_with_cap()
Just like get_or_try_new()
but caps the size of the pool. Once len()
== cap
then it waits for an open lease.
§Errors
Returns an error if the stored initializer errors
sourcepub fn clear(&self)
pub fn clear(&self)
Sets the size of the pool to zero
This will disassociate all current Lease
es and when they go out of scope the objects they’re
holding will be dropped