Skip to content

Commit 88bfa6e

Browse files
committed
Apply clippy checks
1 parent c3be542 commit 88bfa6e

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

  • crates/charon/src/expbackoff

crates/charon/src/expbackoff/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ where
3434
let mut backoff = self.base_delay;
3535
let mut retries = self.retries;
3636

37+
// SAFE: Substraction is only performed when retries > 0
38+
#[allow(clippy::arithmetic_side_effects)]
3739
while backoff < self.max_delay && retries > 0 {
3840
backoff = backoff.mul_f64(self.multiplier);
3941
retries -= 1;
@@ -50,7 +52,7 @@ where
5052

5153
/// Assume a retry has occurred.
5254
pub fn tried(&mut self) {
53-
self.retries += 1;
55+
self.retries = self.retries.saturating_add(1);
5456
}
5557

5658
/// Resets the backoff duration to the base delay.
@@ -89,14 +91,14 @@ pub struct ExponentialBackoffBuilder<R = HasherRng> {
8991
rng: R,
9092
}
9193

92-
impl ExponentialBackoffBuilder {
94+
impl Default for ExponentialBackoffBuilder {
9395
/// Backoff configuration with the default values specified at https://github.com/grpc/grpc/blob/master/doc/connection-backoff.md.
9496
///
9597
/// This should be useful for callers who want to configure backoff with
9698
/// non-default values only for a subset of the options.
9799
///
98100
/// Copied from [google.golang.org/grpc@v1.48.0/backoff/backoff.go]
99-
pub fn default() -> Self {
101+
fn default() -> Self {
100102
Self {
101103
base_delay: time::Duration::from_secs(1),
102104
multiplier: 1.6,
@@ -105,7 +107,9 @@ impl ExponentialBackoffBuilder {
105107
rng: HasherRng::default(),
106108
}
107109
}
110+
}
108111

112+
impl ExponentialBackoffBuilder {
109113
/// Common configuration for fast backoff.
110114
pub fn fast_config() -> Self {
111115
Self {
@@ -220,7 +224,7 @@ mod tests {
220224
Duration::from_secs(1),
221225
Duration::from_secs(1) + Duration::from_millis(600),
222226
Duration::from_secs(2) + Duration::from_millis(560),
223-
Duration::from_secs(4) + Duration::from_millis(090),
227+
Duration::from_secs(4) + Duration::from_millis(90),
224228
Duration::from_secs(6) + Duration::from_millis(550),
225229
Duration::from_secs(10) + Duration::from_millis(480),
226230
Duration::from_secs(16) + Duration::from_millis(770),
@@ -281,6 +285,8 @@ mod tests {
281285
fn assert_test_case(tc: TestCase) {
282286
let mut instance = tc.config.with_rng(Const(tc.rng)).build().unwrap();
283287

288+
// SAFE: Used for testing purposes only
289+
#[allow(clippy::arithmetic_side_effects)]
284290
for expected in tc.backoffs {
285291
let duration = instance.backoff();
286292
instance.tried();

0 commit comments

Comments
 (0)