Struct mobc::Builder

source ·
pub struct Builder<M> { /* private fields */ }
Expand description

A builder for a connection pool.

Implementations§

source§

impl<M: Manager> Builder<M>

source

pub fn new() -> Self

Constructs a new Builder.

Parameters are initialized with their default values.

source

pub fn max_open(self, max_open: u64) -> Self

Sets the maximum number of connections managed by the pool.

  • 0 means unlimited.
  • Defaults to 10.
source

pub fn max_idle(self, max_idle: u64) -> Self

Sets the maximum idle connection count maintained by the pool.

The pool will maintain at most this many idle connections at all times, while respecting the value of max_open.

  • 0 means unlimited (limited only by max_open).
  • Defaults to 2.
source

pub fn test_on_check_out(self, health_check: bool) -> Builder<M>

If true, the health of a connection will be verified via a call to Manager::check before it is checked out of the pool.

  • Defaults to true.
source

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

Sets the maximum lifetime of connections in the pool.

Expired connections may be closed lazily before reuse.

  • None means reuse forever.
  • Defaults to None.
§Panics

Panics if max_lifetime is the zero Duration.

source

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

Sets the maximum lifetime of connection to be idle in the pool, resetting the timer when connection is used.

Expired connections may be closed lazily before reuse.

  • None means reuse forever.
  • Defaults to None.
§Panics

Panics if max_idle_lifetime is the zero Duration.

source

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

Sets the get timeout used by the pool.

Calls to Pool::get will wait this long for a connection to become available before returning an error.

  • None means never timeout.
  • Defaults to 30 seconds.
§Panics

Panics if connection_timeout is the zero duration

source

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

Sets the interval how often a connection will be checked when returning an existing connection from the pool. If set to None, a connection is checked every time when returning from the pool. Must be used together with test_on_check_out set to true, otherwise does nothing.

  • None means a connection is checked every time when returning from the pool.
  • Defaults to None.
§Panics

Panics if connection_timeout is the zero duration

source

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

Consumes the builder, returning a new, initialized pool.

Trait Implementations§

source§

impl<M> Default for Builder<M>

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<M> Freeze for Builder<M>

§

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

§

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

§

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

§

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

§

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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>,

§

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

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more