Struct mobc::Pool

source ·
pub struct Pool<M: Manager>(/* private fields */);
Expand description

A generic connection pool.

Implementations§

source§

impl<M: Manager> Pool<M>

source

pub fn new(manager: M) -> Pool<M>

Creates a new connection pool with a default configuration.

source

pub fn builder() -> Builder<M>

Returns a builder type to configure a new pool.

source

pub async fn set_max_open_conns(&self, n: u64)

Sets the maximum number of connections managed by the pool.

0 means unlimited, defaults to 10.

source

pub async fn set_max_idle_conns(&self, n: u64)

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 async fn set_conn_max_lifetime(&self, max_lifetime: Option<Duration>)

Sets the maximum lifetime of connections in the pool.

Expired connections may be closed lazily before reuse.

None meas reuse forever. Defaults to None.

§Panics

Panics if max_lifetime is the zero Duration.

source

pub async fn get(&self) -> Result<Connection<M>, Error<M::Error>>

Returns a single connection by either opening a new connection or returning an existing connection from the connection pool. Conn will block until either a connection is returned or timeout.

source

pub async fn get_timeout( &self, duration: Duration ) -> Result<Connection<M>, Error<M::Error>>

Retrieves a connection from the pool, waiting for at most timeout

The given timeout will be used instead of the configured connection timeout.

source

pub async fn state(&self) -> State

Returns information about the current state of the pool. It is better to use the metrics than this method, this method requires a lock on the internals

Trait Implementations§

source§

impl<M: Manager> Clone for Pool<M>

Returns a new Pool referencing the same state as self.

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<M: Manager> Debug for Pool<M>

source§

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

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

impl<M: Manager> Drop for Pool<M>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<M> Freeze for Pool<M>
where M: Sync + Send + 'static,

§

impl<M> !RefUnwindSafe for Pool<M>

§

impl<M> Send for Pool<M>
where M: Sync + Send + 'static,

§

impl<M> Sync for Pool<M>
where M: Sync + Send + 'static,

§

impl<M> Unpin for Pool<M>
where M: Sync + Send + 'static,

§

impl<M> !UnwindSafe for Pool<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> 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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