From 90d0b35ae5bcff1796f8cec200d9ecf75d26d414 Mon Sep 17 00:00:00 2001 From: Ulrik Date: Tue, 15 Sep 2020 16:59:40 +0200 Subject: [PATCH] ConnectionPool::default: Explicit implementation The auto-derived implementation would have unexpectedly initialized the `usize` fields to 0. Having a `::default()` leading to an unuseable value is counter-intuitive. --- src/pool.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/pool.rs b/src/pool.rs index ae2dd3f..2917c69 100644 --- a/src/pool.rs +++ b/src/pool.rs @@ -19,7 +19,7 @@ const DEFAULT_MAX_IDLE_CONNECTIONS_PER_HOST: usize = 1; /// Invariant: Each PoolKey exists in recycle at most once and lru at most once. /// /// *Internal API* -#[derive(Default, Debug)] +#[derive(Debug)] pub(crate) struct ConnectionPool { // the actual pooled connection. however only one per hostname:port. recycle: HashMap>, @@ -32,14 +32,21 @@ pub(crate) struct ConnectionPool { max_idle_connections_per_host: usize, } -impl ConnectionPool { - pub fn new() -> Self { - ConnectionPool { +impl Default for ConnectionPool { + fn default() -> Self { + Self { max_idle_connections: DEFAULT_MAX_IDLE_CONNECTIONS, max_idle_connections_per_host: DEFAULT_MAX_IDLE_CONNECTIONS_PER_HOST, - ..Default::default() + recycle: HashMap::default(), + lru: VecDeque::default(), } } +} + +impl ConnectionPool { + pub fn new() -> Self { + Self::default() + } pub fn set_max_idle_connections(&mut self, max_connections: usize) { if self.max_idle_connections == max_connections {