refactor(client): clean up client config fields

This commit is contained in:
Sean McArthur
2018-12-05 12:17:03 -08:00
parent 155dc41e70
commit 4b3747110a
3 changed files with 62 additions and 99 deletions

View File

@@ -85,33 +85,26 @@ struct PoolInner<T> {
// doesn't need it!
struct WeakOpt<T>(Option<Weak<T>>);
// Newtypes to act as keyword arguments for `Pool::new`...
// FIXME: allow() required due to `impl Trait` leaking types to this lint
#[allow(missing_debug_implementations)]
pub(super) struct Enabled(pub(super) bool);
// FIXME: allow() required due to `impl Trait` leaking types to this lint
#[allow(missing_debug_implementations)]
pub(super) struct IdleTimeout(pub(super) Option<Duration>);
// FIXME: allow() required due to `impl Trait` leaking types to this lint
#[allow(missing_debug_implementations)]
pub(super) struct MaxIdlePerHost(pub(super) usize);
#[derive(Clone, Copy, Debug)]
pub(super) struct Config {
pub(super) enabled: bool,
pub(super) keep_alive_timeout: Option<Duration>,
pub(super) max_idle_per_host: usize,
}
impl<T> Pool<T> {
pub fn new(enabled: Enabled, timeout: IdleTimeout, max_idle: MaxIdlePerHost, __exec: &Exec) -> Pool<T> {
let inner = if enabled.0 {
pub fn new(config: Config, __exec: &Exec) -> Pool<T> {
let inner = if config.enabled {
Some(Arc::new(Mutex::new(PoolInner {
connecting: HashSet::new(),
idle: HashMap::new(),
#[cfg(feature = "runtime")]
idle_interval_ref: None,
max_idle_per_host: max_idle.0,
max_idle_per_host: config.max_idle_per_host,
waiters: HashMap::new(),
#[cfg(feature = "runtime")]
exec: __exec.clone(),
timeout: timeout.0,
timeout: config.keep_alive_timeout,
})))
} else {
None