File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed
Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -140,6 +140,16 @@ const_assert!(
140140 PoolConstraints :: DEFAULT . min <= PoolConstraints :: DEFAULT . max,
141141) ;
142142
143+ const_assert ! (
144+ _POOL_CONSTRAINTS_MIN_IS_NONZERO,
145+ PoolConstraints :: DEFAULT . min > 0
146+ ) ;
147+
148+ const_assert ! (
149+ _POOL_CONSTRAINTS_MAX_IS_NONZERO,
150+ PoolConstraints :: DEFAULT . max > 0
151+ ) ;
152+
143153pub struct Assert < const L : usize , const R : usize > ;
144154impl < const L : usize , const R : usize > Assert < L , R > {
145155 pub const LEQ : usize = R - L ;
@@ -169,15 +179,18 @@ impl PoolConstraints {
169179 /// # Ok(()) }
170180 /// ```
171181 pub fn new ( min : usize , max : usize ) -> Option < PoolConstraints > {
172- if min <= max {
173- Some ( PoolConstraints { min , max } )
174- } else {
175- None
182+ match ( min, max) {
183+ ( 0 , 0 ) => None ,
184+ ( min , max ) if min <= max => Some ( PoolConstraints { min , max } ) ,
185+ _ => None ,
176186 }
177187 }
178188
179189 pub const fn new_const < const MIN : usize , const MAX : usize > ( ) -> PoolConstraints {
180190 gte :: < MIN , MAX > ( ) ;
191+
192+ assert ! ( MAX > 0 ) ;
193+
181194 PoolConstraints { min : MIN , max : MAX }
182195 }
183196
Original file line number Diff line number Diff line change @@ -508,6 +508,18 @@ mod test {
508508 assert ! ( pool. try_get_conn( Duration :: from_millis( 357 ) ) . is_ok( ) ) ;
509509 }
510510
511+ #[ test]
512+ fn should_be_none_if_pool_size_zero_zero ( ) {
513+ let pool_constraints = PoolConstraints :: new ( 0 , 0 ) ;
514+ assert ! ( pool_constraints. is_none( ) ) ;
515+ }
516+
517+ #[ test]
518+ #[ should_panic]
519+ fn should_panic_if_pool_size_zero_zero ( ) {
520+ PoolConstraints :: new_const :: < 0 , 0 > ( ) ;
521+ }
522+
511523 #[ test]
512524 fn should_execute_statements_on_PooledConn ( ) {
513525 let pool = Pool :: new ( get_opts ( ) ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments