pub struct Builder<M: Manager> { /* private fields */ }std only.Expand description
A fluent builder for a Pool.
Created by Pool::builder. Each setter consumes and returns the builder, so
calls chain; build validates the configuration and
pre-creates the min_idle resources.
§Examples
use std::time::Duration;
use pool_mod::{Manager, Pool};
use std::convert::Infallible;
let pool = Pool::builder(M)
.max_size(32)
.min_idle(4)
.idle_timeout(Some(Duration::from_secs(600)))
.max_lifetime(Some(Duration::from_secs(3600)))
.build()
.expect("configuration is valid");
assert_eq!(pool.status().idle, 4);Implementations§
Source§impl<M: Manager> Builder<M>
impl<M: Manager> Builder<M>
Sourcepub fn new(manager: M) -> Self
pub fn new(manager: M) -> Self
Create a builder for manager seeded with the default configuration.
Sourcepub fn max_size(self, max_size: usize) -> Self
pub fn max_size(self, max_size: usize) -> Self
Set the maximum number of resources the pool may own at once.
Sourcepub fn min_idle(self, min_idle: usize) -> Self
pub fn min_idle(self, min_idle: usize) -> Self
Set how many resources to create up front and keep ready.
Sourcepub fn create_timeout(self, timeout: Option<Duration>) -> Self
pub fn create_timeout(self, timeout: Option<Duration>) -> Self
Set how long Pool::get waits when the pool is saturated. None waits
indefinitely.
Sourcepub fn idle_timeout(self, timeout: Option<Duration>) -> Self
pub fn idle_timeout(self, timeout: Option<Duration>) -> Self
Set the idle-expiry window. None disables idle expiry.
Sourcepub fn max_lifetime(self, lifetime: Option<Duration>) -> Self
pub fn max_lifetime(self, lifetime: Option<Duration>) -> Self
Set the maximum resource lifetime. None disables lifetime expiry.
Sourcepub fn config(self, config: PoolConfig) -> Self
pub fn config(self, config: PoolConfig) -> Self
Replace the entire configuration with config.
Useful when the configuration is loaded from a file rather than assembled setter by setter.
Sourcepub fn build(self) -> Result<Pool<M>, Error<M::Error>>
pub fn build(self) -> Result<Pool<M>, Error<M::Error>>
Validate the configuration, build the pool, and pre-create min_idle
resources.
§Errors
Error::InvalidConfigifmax_sizeis zero ormin_idleexceedsmax_size.Error::Backendif creating one of themin_idleresources fails; any already-created resources are dropped before returning.
§Examples
use pool_mod::{Error, Manager, Pool};
use std::convert::Infallible;
let invalid = Pool::builder(M).max_size(0).build();
assert!(matches!(invalid, Err(Error::InvalidConfig(_))));