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>
impl<M: Manager> Pool<M>
Sourcepub async fn get(&self) -> Result<ConnectionGuard<M>, M::Error>
pub async fn get(&self) -> Result<ConnectionGuard<M>, M::Error>
Get connection from pool (blocks until available)
Sourcepub async fn get_timeout(
&self,
d: Option<Duration>,
) -> Result<ConnectionGuard<M>, M::Error>
pub async fn get_timeout( &self, d: Option<Duration>, ) -> Result<ConnectionGuard<M>, M::Error>
Get connection with optional timeout
Sourcepub fn set_max_open(&self, n: u64)
pub fn set_max_open(&self, n: u64)
Set maximum open connections
pub fn get_max_open(&self) -> u64
Sourcepub fn set_max_idle_conns(&self, n: u64)
pub fn set_max_idle_conns(&self, n: u64)
Set maximum number of idle connections
Sourcepub fn get_max_idle_conns(&self) -> u64
pub fn get_max_idle_conns(&self) -> u64
Get maximum number of idle connections
pub fn recycle(&self, arg: M::Connection)
Sourcepub fn set_timeout_check(&self, duration: Option<Duration>)
pub fn set_timeout_check(&self, duration: Option<Duration>)
Set the timeout for checking connections in the pool.
Sourcepub fn get_timeout_check(&self) -> Option<Duration>
pub fn get_timeout_check(&self) -> Option<Duration>
Set the timeout for checking connections in the pool.
Sourcepub fn downcast_manager<T>(&self) -> Option<&T>where
T: Manager,
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
§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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)