From f0644f76b260dfeb55d3ae9feeba922f4f2c508c Mon Sep 17 00:00:00 2001 From: Alexander Weiss Date: Thu, 11 Aug 2022 21:37:50 +0200 Subject: [PATCH] impl Backoff for Option --- src/backoff.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/backoff.rs b/src/backoff.rs index ce674a9..a782b75 100644 --- a/src/backoff.rs +++ b/src/backoff.rs @@ -22,6 +22,20 @@ impl Backoff for Box { } } +/// 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 Backoff for Option { + fn next_backoff(&mut self) -> Option { + 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 {}