#![allow(dead_code)]
use std::time::Duration;
#[derive(Copy, Clone)]
pub struct PoolConfig {
pub max_total_per_key: usize,
pub max_wait: Option<Duration>,
pub test_on_borrow: bool,
pub test_on_return: bool,
pub test_while_idle: bool,
pub test_timeout: Duration,
pub time_between_eviction_runs: Duration,
pub min_evictable_idle_duration: Duration,
pub max_lifetime: Duration,
pub idle_timeout: Duration,
pub lifo: bool,
}
impl Default for PoolConfig {
fn default() -> Self {
Self {
max_total_per_key: 50,
max_wait: None,
test_on_borrow: false,
test_on_return: false,
test_while_idle: true,
test_timeout: Duration::from_secs(3),
time_between_eviction_runs: Duration::from_secs(2 * 60),
min_evictable_idle_duration: Duration::from_secs(15),
max_lifetime: Duration::MAX,
idle_timeout: Duration::MAX,
lifo: true,
}
}
}
impl PoolConfig {
pub fn new() -> Self {
Self::default()
}
pub fn max_total_per_key(mut self, max_total_per_key: usize) -> Self {
self.max_total_per_key = max_total_per_key;
self
}
pub fn max_wait(mut self, max_wait: Option<Duration>) -> Self {
self.max_wait = max_wait;
self
}
pub fn test_on_borrow(mut self, test_on_borrow: bool) -> Self {
self.test_on_borrow = test_on_borrow;
self
}
pub fn test_on_return(mut self, test_on_return: bool) -> Self {
self.test_on_return = test_on_return;
self
}
pub fn test_while_idle(mut self, test_while_idle: bool) -> Self {
self.test_while_idle = test_while_idle;
self
}
pub fn test_timeout(mut self, test_timeout: Duration) -> Self {
self.test_timeout = test_timeout;
self
}
pub fn time_between_eviction_runs(mut self, time_between_eviction_runs: Duration) -> Self {
self.time_between_eviction_runs = time_between_eviction_runs;
self
}
pub fn min_evictable_idle_duration(mut self, min_evictable_idle_duration: Duration) -> Self {
self.min_evictable_idle_duration = min_evictable_idle_duration;
self
}
pub fn max_lifetime(mut self, max_lifetime: Duration) -> Self {
self.max_lifetime = max_lifetime;
self
}
pub fn idle_timeout(mut self, idle_timeout: Duration) -> Self {
self.idle_timeout = idle_timeout;
self
}
pub fn lifo(mut self, lifo: bool) -> Self {
self.lifo = lifo;
self
}
}