diff --git a/src/conn/opts/pool_opts.rs b/src/conn/opts/pool_opts.rs index d283eb7..a36cd72 100644 --- a/src/conn/opts/pool_opts.rs +++ b/src/conn/opts/pool_opts.rs @@ -140,6 +140,16 @@ const_assert!( PoolConstraints::DEFAULT.min <= PoolConstraints::DEFAULT.max, ); +const_assert!( + _POOL_CONSTRAINTS_MIN_IS_NONZERO, + PoolConstraints::DEFAULT.min > 0 +); + +const_assert!( + _POOL_CONSTRAINTS_MAX_IS_NONZERO, + PoolConstraints::DEFAULT.max > 0 +); + pub struct Assert; impl Assert { pub const LEQ: usize = R - L; @@ -169,15 +179,18 @@ impl PoolConstraints { /// # Ok(()) } /// ``` pub fn new(min: usize, max: usize) -> Option { - if min <= max { - Some(PoolConstraints { min, max }) - } else { - None + match (min, max) { + (0, 0) => None, + (min, max) if min <= max => Some(PoolConstraints { min, max }), + _ => None, } } pub const fn new_const() -> PoolConstraints { gte::(); + + assert!(MAX > 0); + PoolConstraints { min: MIN, max: MAX } } diff --git a/src/conn/pool/mod.rs b/src/conn/pool/mod.rs index 2c0ff94..a66f3c6 100644 --- a/src/conn/pool/mod.rs +++ b/src/conn/pool/mod.rs @@ -498,6 +498,18 @@ mod test { assert!(pool.try_get_conn(Duration::from_millis(357)).is_ok()); } + #[test] + fn should_be_none_if_pool_size_zero_zero() { + let pool_constraints = PoolConstraints::new(0, 0); + assert!(pool_constraints.is_none()); + } + + #[test] + #[should_panic] + fn should_panic_if_pool_size_zero_zero() { + PoolConstraints::new_const::<0, 0>(); + } + #[test] fn should_execute_statements_on_PooledConn() { let pool = Pool::new(get_opts()).unwrap();