From 8c266391f33f6a86d1c0aaa410e7a05fc1df35b0 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 1 Feb 2024 10:44:15 +0100 Subject: [PATCH] bb8: replace manual implementation of saturating_sub() --- bb8/src/internals.rs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/bb8/src/internals.rs b/bb8/src/internals.rs index 8aa79d6..ed153f0 100644 --- a/bb8/src/internals.rs +++ b/bb8/src/internals.rs @@ -125,24 +125,13 @@ where pub(crate) fn wanted(&mut self, config: &Builder) -> ApprovalIter { let available = self.conns.len() as u32 + self.pending_conns; let min_idle = config.min_idle.unwrap_or(0); - let wanted = if available < min_idle { - min_idle - available - } else { - 0 - }; - + let wanted = min_idle.saturating_sub(available); self.approvals(config, wanted) } fn approvals(&mut self, config: &Builder, num: u32) -> ApprovalIter { let current = self.num_conns + self.pending_conns; - let allowed = if current < config.max_size { - config.max_size - current - } else { - 0 - }; - - let num = min(num, allowed); + let num = min(num, config.max_size.saturating_sub(current)); self.pending_conns += num; ApprovalIter { num: num as usize } }