Skip to content

Commit d60277b

Browse files
committed
Remove explicit type parameter requirement
1 parent 1faf015 commit d60277b

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

  • crates/charon/src/expbackoff

crates/charon/src/expbackoff/mod.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,31 @@ where
7373
}
7474
}
7575

76+
type Result<T> = std::result::Result<T, InvalidBackoff>;
77+
78+
/// Error indicating an invalid backoff configuration.
79+
#[derive(Debug, thiserror::Error)]
80+
#[error("Invalid backoff configuration: {0}")]
81+
pub struct InvalidBackoff(&'static str);
82+
7683
/// Builder pattern to create an [`ExponentialBackoff`] instance.
77-
pub struct ExponentialBackoffBuilder<R> {
84+
pub struct ExponentialBackoffBuilder<R = HasherRng> {
7885
base_delay: time::Duration,
7986
multiplier: f64,
8087
jitter: f64,
8188
max_delay: time::Duration,
8289
rng: R,
8390
}
8491

85-
type Result<T> = std::result::Result<T, InvalidBackoff>;
86-
87-
/// Error indicating an invalid backoff configuration.
88-
#[derive(Debug, thiserror::Error)]
89-
#[error("Invalid backoff configuration: {0}")]
90-
pub struct InvalidBackoff(&'static str);
91-
92-
impl<R> ExponentialBackoffBuilder<R> {
92+
impl ExponentialBackoffBuilder {
9393
/// Backoff configuration with the default values specified at https://github.com/grpc/grpc/blob/master/doc/connection-backoff.md.
9494
///
9595
/// This should be useful for callers who want to configure backoff with
9696
/// non-default values only for a subset of the options.
9797
///
9898
/// Copied from [google.golang.org/grpc@v1.48.0/backoff/backoff.go]
99-
pub fn default() -> ExponentialBackoffBuilder<HasherRng> {
100-
ExponentialBackoffBuilder {
99+
pub fn default() -> Self {
100+
Self {
101101
base_delay: time::Duration::from_secs(1),
102102
multiplier: 1.6,
103103
jitter: 0.2,
@@ -107,16 +107,18 @@ impl<R> ExponentialBackoffBuilder<R> {
107107
}
108108

109109
/// Common configuration for fast backoff.
110-
pub fn fast_config() -> ExponentialBackoffBuilder<HasherRng> {
111-
ExponentialBackoffBuilder {
110+
pub fn fast_config() -> Self {
111+
Self {
112112
base_delay: time::Duration::from_millis(100),
113113
multiplier: 1.6,
114114
jitter: 0.2,
115115
max_delay: time::Duration::from_secs(5),
116116
rng: HasherRng::default(),
117117
}
118118
}
119+
}
119120

121+
impl<R> ExponentialBackoffBuilder<R> {
120122
/// Set the amount of time to backoff after the first failure.
121123
pub fn with_base_delay(mut self, delay: time::Duration) -> Self {
122124
self.base_delay = delay;
@@ -189,7 +191,7 @@ impl<R> ExponentialBackoffBuilder<R> {
189191
mod tests {
190192
use crate::expbackoff::ExponentialBackoffBuilder;
191193
use core::time::Duration;
192-
use tower::util::rng::{HasherRng, Rng};
194+
use tower::util::rng::Rng;
193195

194196
struct Const(f64);
195197

@@ -204,15 +206,15 @@ mod tests {
204206
}
205207

206208
struct TestCase {
207-
config: ExponentialBackoffBuilder<HasherRng>,
209+
config: ExponentialBackoffBuilder,
208210
rng: f64,
209211
backoffs: Vec<Duration>,
210212
}
211213

212214
#[test]
213215
fn default_config() {
214216
assert_test_case(TestCase {
215-
config: ExponentialBackoffBuilder::<HasherRng>::default(),
217+
config: ExponentialBackoffBuilder::default(),
216218
rng: 0.5,
217219
backoffs: vec![
218220
Duration::from_secs(1),
@@ -235,7 +237,7 @@ mod tests {
235237
#[test]
236238
fn default_config_max_jitter() {
237239
assert_test_case(TestCase {
238-
config: ExponentialBackoffBuilder::<HasherRng>::default(),
240+
config: ExponentialBackoffBuilder::default(),
239241
rng: 1.0,
240242
backoffs: vec![
241243
Duration::from_secs(1),
@@ -258,7 +260,7 @@ mod tests {
258260
#[test]
259261
fn fast() {
260262
assert_test_case(TestCase {
261-
config: ExponentialBackoffBuilder::<HasherRng>::fast_config(),
263+
config: ExponentialBackoffBuilder::fast_config(),
262264
rng: 0.5,
263265
backoffs: vec![
264266
Duration::from_millis(100),

0 commit comments

Comments
 (0)