Skip to content

Commit 8c26639

Browse files
committed
bb8: replace manual implementation of saturating_sub()
1 parent ced6412 commit 8c26639

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

bb8/src/internals.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -125,24 +125,13 @@ where
125125
pub(crate) fn wanted(&mut self, config: &Builder<M>) -> ApprovalIter {
126126
let available = self.conns.len() as u32 + self.pending_conns;
127127
let min_idle = config.min_idle.unwrap_or(0);
128-
let wanted = if available < min_idle {
129-
min_idle - available
130-
} else {
131-
0
132-
};
133-
128+
let wanted = min_idle.saturating_sub(available);
134129
self.approvals(config, wanted)
135130
}
136131

137132
fn approvals(&mut self, config: &Builder<M>, num: u32) -> ApprovalIter {
138133
let current = self.num_conns + self.pending_conns;
139-
let allowed = if current < config.max_size {
140-
config.max_size - current
141-
} else {
142-
0
143-
};
144-
145-
let num = min(num, allowed);
134+
let num = min(num, config.max_size.saturating_sub(current));
146135
self.pending_conns += num;
147136
ApprovalIter { num: num as usize }
148137
}

0 commit comments

Comments
 (0)