pub struct Pool<M: Manager, W: From<Object<M>> = Object<M>> { /* private fields */ }
Available on crate feature managed only.
Expand description

Generic object and connection pool.

This struct can be cloned and transferred across thread boundaries and uses reference counting for its internal state.

Implementations

Instantiates a builder for a new Pool.

This is the only way to create a Pool instance.

Retrieves an Object from this Pool or waits for one to become available.

Errors

See PoolError for details.

👎 Deprecated since 0.9.3:

The name of this method is highly misleading. Please use timeout_get instead. e.g. pool.timeout_get(&Timeouts { wait: Some(Duration::ZERO), ..pool.timeouts() })

Retrieves an Object from this Pool and doesn’t wait if there is currently no Object available and the maximum Pool size has been reached.

Errors

See PoolError for details.

Retrieves an Object from this Pool using a different timeout than the configured one.

Errors

See PoolError for details.

Resize the pool. This change the max_size of the pool dropping excess objects and/or making space for new ones.

If the pool is closed this method does nothing. The Pool::status method always reports a max_size of 0 for closed pools.

Retains only the objects specified by the given function.

This function is typically used to remove objects from the pool based on their current state or metrics.

Caution: This function blocks the entire pool while it is running. Therefore the given function should not block.

The following example starts a background task that runs every 30 seconds and removes objects from the pool that haven’t been used for more than one minute.

let interval = Duration::from_secs(30);
let max_age = Duration::from_secs(60);
tokio::spawn(async move {
    loop {
        tokio::time::sleep(interval).await;
        pool.retain(|_, metrics| metrics.last_used() < max_age);
    }
});

Get current timeout configuration

Closes this Pool.

All current and future tasks waiting for Objects will return PoolError::Closed immediately.

This operation resizes the pool to 0.

Indicates whether this Pool has been closed.

Retrieves Status of this Pool.

Returns Manager of this Pool.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.