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

impl Backoff for Option<Backoff> #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/backoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ impl<B: Backoff + ?Sized> Backoff for Box<B> {
}
}

/// Option of a Backoff retries the operation with backoff if the Option is Some(backoff)
/// and never retries the operation if the Option is None
impl<B: Backoff> Backoff for Option<B> {
fn next_backoff(&mut self) -> Option<Duration> {
self.as_mut().and_then(|b| b.next_backoff())
}

fn reset(&mut self) {
if let Some(b) = self {
b.reset()
}
}
}

/// Immediately retry the operation.
#[derive(Debug)]
pub struct Zero {}
Expand Down