Skip to main content

Builder

Struct Builder 

Source
pub struct Builder<M: Manager> { /* private fields */ }
Available on crate feature 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>

Source

pub fn new(manager: M) -> Self

Create a builder for manager seeded with the default configuration.

Source

pub fn max_size(self, max_size: usize) -> Self

Set the maximum number of resources the pool may own at once.

Source

pub fn min_idle(self, min_idle: usize) -> Self

Set how many resources to create up front and keep ready.

Source

pub fn create_timeout(self, timeout: Option<Duration>) -> Self

Set how long Pool::get waits when the pool is saturated. None waits indefinitely.

Source

pub fn idle_timeout(self, timeout: Option<Duration>) -> Self

Set the idle-expiry window. None disables idle expiry.

Source

pub fn max_lifetime(self, lifetime: Option<Duration>) -> Self

Set the maximum resource lifetime. None disables lifetime expiry.

Source

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.

Source

pub fn build(self) -> Result<Pool<M>, Error<M::Error>>

Validate the configuration, build the pool, and pre-create min_idle resources.

§Errors
  • Error::InvalidConfig if max_size is zero or min_idle exceeds max_size.
  • Error::Backend if creating one of the min_idle resources 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(_))));

Auto Trait Implementations§

§

impl<M> Freeze for Builder<M>
where M: Freeze,

§

impl<M> RefUnwindSafe for Builder<M>
where M: RefUnwindSafe,

§

impl<M> Send for Builder<M>

§

impl<M> Sync for Builder<M>

§

impl<M> Unpin for Builder<M>
where M: Unpin,

§

impl<M> UnsafeUnpin for Builder<M>
where M: UnsafeUnpin,

§

impl<M> UnwindSafe for Builder<M>
where M: UnwindSafe,

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> 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, 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.