diesel::r2d2

Struct Builder

Source
pub struct Builder<M>{ /* private fields */ }
Available on crate feature r2d2 only.
Expand description

A builder for a connection pool.

Implementations§

Source§

impl<M> Builder<M>

Source

pub fn new() -> Builder<M>

Constructs a new Builder.

Parameters are initialized with their default values.

Source

pub fn max_size(self, max_size: u32) -> Builder<M>

Sets the maximum number of connections managed by the pool.

Defaults to 10.

§Panics

Panics if max_size is 0.

Source

pub fn min_idle(self, min_idle: Option<u32>) -> Builder<M>

Sets the minimum idle connection count maintained by the pool.

If set, the pool will try to maintain at least this many idle connections at all times, while respecting the value of max_size.

Defaults to None (equivalent to the value of max_size).

Source

pub fn thread_pool(self, thread_pool: Arc<ScheduledThreadPool>) -> Builder<M>

Sets the thread pool used for asynchronous operations such as connection creation.

Defaults to a new pool with 3 threads.

Source

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

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

Defaults to true.

Source

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

Sets the maximum lifetime of connections in the pool.

If set, connections will be closed after existing for at most 30 seconds beyond this duration.

If a connection reaches its maximum lifetime while checked out it will be closed when it is returned to the pool.

Defaults to 30 minutes.

§Panics

Panics if max_lifetime is the zero Duration.

Source

pub fn idle_timeout(self, idle_timeout: Option<Duration>) -> Builder<M>

Sets the idle timeout used by the pool.

If set, connections will be closed after sitting idle for at most 30 seconds beyond this duration.

Defaults to 10 minutes.

§Panics

Panics if idle_timeout is the zero Duration.

Source

pub fn connection_timeout(self, connection_timeout: Duration) -> Builder<M>

Sets the connection timeout used by the pool.

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

Defaults to 30 seconds.

§Panics

Panics if connection_timeout is the zero duration

Source

pub fn error_handler( self, error_handler: Box<dyn HandleError<<M as ManageConnection>::Error>>, ) -> Builder<M>

Sets the handler for errors reported in the pool.

Defaults to the LoggingErrorHandler.

Source

pub fn event_handler(self, event_handler: Box<dyn HandleEvent>) -> Builder<M>

Sets the handler for events reported by the pool.

Defaults to the NopEventHandler.

Source

pub fn connection_customizer( self, connection_customizer: Box<dyn CustomizeConnection<<M as ManageConnection>::Connection, <M as ManageConnection>::Error>>, ) -> Builder<M>

Sets the connection customizer used by the pool.

Defaults to the NopConnectionCustomizer.

Source

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

Consumes the builder, returning a new, initialized pool.

It will block until the pool has established its configured minimum number of connections, or it times out.

§Errors

Returns an error if the pool is unable to open its minimum number of connections.

§Panics

Panics if min_idle is greater than max_size.

Source

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

Consumes the builder, returning a new pool.

Unlike build, this method does not wait for any connections to be established before returning.

§Panics

Panics if min_idle is greater than max_size.

Trait Implementations§

Source§

impl<M> Debug for Builder<M>

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<M> Default for Builder<M>

Source§

fn default() -> Builder<M>

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

Auto Trait Implementations§

§

impl<M> Freeze for Builder<M>

§

impl<M> !RefUnwindSafe for Builder<M>

§

impl<M> Send for Builder<M>

§

impl<M> Sync for Builder<M>

§

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

§

impl<M> !UnwindSafe for Builder<M>

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

Source§

fn into_sql<T>(self) -> AsExprOf<Self, T>

Convert self to an expression for Diesel’s query builder. Read more
Source§

fn as_sql<'a, T>(&'a self) -> AsExprOf<&'a Self, T>
where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T