use std::time::Duration;
#[derive(Debug)]
pub struct Config {
pub(crate) min_size: usize,
pub(crate) max_size: usize,
pub(crate) idle_queue_size: usize,
pub(crate) test_on_check_out: bool,
pub(crate) connect_timeout: Option<Duration>,
}
impl Config {
pub fn new() -> Self {
Self::default()
}
pub fn connection_timeout(mut self, timeout: Duration) -> Self {
self.connect_timeout = Some(timeout);
self
}
pub fn test_on_check_out(mut self, test_on_check_out: bool) -> Self {
self.test_on_check_out = test_on_check_out;
self
}
pub fn min_size(mut self, min_size: usize) -> Self {
self.min_size = min_size;
self
}
pub fn max_size(mut self, max_size: usize) -> Self {
self.max_size = max_size;
self.idle_queue_size = max_size * IDLE_QUEUE_SIZE_FACTOR;
self
}
}
const MIN_SIZE: usize = 1;
const MAX_SIZE: usize = 10;
const IDLE_QUEUE_SIZE_FACTOR: usize = 2;
impl Default for Config {
fn default() -> Self {
Config {
max_size: MAX_SIZE,
min_size: MIN_SIZE,
idle_queue_size: MAX_SIZE * IDLE_QUEUE_SIZE_FACTOR,
test_on_check_out: true,
connect_timeout: None,
}
}
}