Pool

Struct Pool 

Source
pub struct Pool<M: Manager> {
    pub manager: Arc<M>,
    pub idle_send: Arc<MTx<M::Connection>>,
    pub idle_recv: Arc<MAsyncRx<M::Connection>>,
    pub max_open: Arc<AtomicU64>,
    pub max_idle: Arc<AtomicU64>,
    pub timeout_check: Arc<AtomicDuration>,
    /* private fields */
}
Expand description

Connection pool with configurable manager and lifecycle management

Fields§

§manager: Arc<M>§idle_send: Arc<MTx<M::Connection>>§idle_recv: Arc<MAsyncRx<M::Connection>>§max_open: Arc<AtomicU64>

Maximum open connections (default: 32)

§max_idle: Arc<AtomicU64>

Maximum idle connections (default: same as max_open)

§timeout_check: Arc<AtomicDuration>

Connection check timeout (default: 10s)

Implementations§

Source§

impl<M: Manager> Pool<M>

Source

pub fn new(m: M) -> Self
where M::Connection: Unpin + Send,

Create new connection pool with default settings

Source

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

Get connection from pool (blocks until available)

Source

pub async fn get_timeout( &self, d: Option<Duration>, ) -> Result<ConnectionGuard<M>, M::Error>

Get connection with optional timeout

Source

pub fn state(&self) -> State

Get current pool state

Source

pub fn set_max_open(&self, n: u64)

Set maximum open connections

Source

pub fn get_max_open(&self) -> u64

Source

pub fn set_max_idle_conns(&self, n: u64)

Set maximum number of idle connections

Source

pub fn get_max_idle_conns(&self) -> u64

Get maximum number of idle connections

Source

pub fn recycle(&self, arg: M::Connection)

Source

pub fn set_timeout_check(&self, duration: Option<Duration>)

Set the timeout for checking connections in the pool.

Source

pub fn get_timeout_check(&self) -> Option<Duration>

Set the timeout for checking connections in the pool.

Source

pub fn downcast_manager<T>(&self) -> Option<&T>
where T: Manager,

Downcast the manager to a concrete type.

This function attempts to downcast the Arc to a specific concrete type. It’s useful when you need to access the underlying manager’s specific methods.

§Example
use fast_pool::{Manager, Pool};
use fast_pool::plugin::{DurationManager, CheckMode};
use std::time::Duration;

struct MyManager;

impl Manager for MyManager {
    type Connection = ();
    type Error = String;

    async fn connect(&self) -> Result<Self::Connection, Self::Error> {
        Ok(())
    }

    async fn check(&self, _conn: &mut Self::Connection) -> Result<(), Self::Error> {
        Ok(())
    }
}

let duration_manager = DurationManager::new(MyManager, CheckMode::SkipInterval(Duration::from_secs(30)));
let pool = Pool::new(duration_manager);

// Downcast to access DurationManager specific methods
if let Some(duration_manager) = pool.downcast_manager::<DurationManager<MyManager>>() {
    // Now you can access DurationManager-specific fields
    let mode = duration_manager.mode.get_mode();
}

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0§

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

Auto Trait Implementations§

§

impl<M> Freeze for Pool<M>

§

impl<M> !RefUnwindSafe for Pool<M>

§

impl<M> Send for Pool<M>

§

impl<M> Sync for Pool<M>

§

impl<M> Unpin for Pool<M>

§

impl<M> !UnwindSafe for Pool<M>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

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

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.