Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow users to use &XxxBuilder #148

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion backon/src/backoff/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,22 @@ impl<B: Backoff> BackoffBuilder for B {
#[cfg(test)]
mod tests {
use super::*;
use crate::{ConstantBuilder, ExponentialBuilder, FibonacciBuilder};

fn test_fn_builder(b: impl BackoffBuilder) {
let _ = b.build();
}

#[test]
fn test_backoff_builder() {
test_fn_builder([Duration::from_secs(1)].into_iter())
test_fn_builder([Duration::from_secs(1)].into_iter());

// Just for test if user can keep using &XxxBuilder.
#[allow(clippy::needless_borrows_for_generic_args)]
{
test_fn_builder(&ConstantBuilder::default());
test_fn_builder(&FibonacciBuilder::default());
test_fn_builder(&ExponentialBuilder::default());
}
}
}
8 changes: 8 additions & 0 deletions backon/src/backoff/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ impl BackoffBuilder for ConstantBuilder {
}
}

impl BackoffBuilder for &ConstantBuilder {
type Backoff = ConstantBackoff;

fn build(self) -> Self::Backoff {
(*self).build()
}
}

/// ConstantBackoff offers a consistent delay with a limited number of retries.
///
/// This backoff strategy is constructed by [`ConstantBuilder`].
Expand Down
8 changes: 8 additions & 0 deletions backon/src/backoff/exponential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ impl BackoffBuilder for ExponentialBuilder {
}
}

impl BackoffBuilder for &ExponentialBuilder {
type Backoff = ExponentialBackoff;

fn build(self) -> Self::Backoff {
(*self).build()
}
}

/// ExponentialBackoff provides a delay with exponential retries.
///
/// This backoff strategy is constructed by [`ExponentialBuilder`].
Expand Down
8 changes: 8 additions & 0 deletions backon/src/backoff/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ impl BackoffBuilder for FibonacciBuilder {
}
}

impl BackoffBuilder for &FibonacciBuilder {
type Backoff = FibonacciBackoff;

fn build(self) -> Self::Backoff {
(*self).build()
}
}

/// FibonacciBackoff offers a delay with Fibonacci-based retries.
///
/// This backoff strategy is constructed by [`FibonacciBuilder`].
Expand Down