pub struct RetryPolicy {
pub initial_delay: Duration,
pub max_delay: Duration,
pub max_attempts: u32,
pub backoff_multiplier: f64,
pub jitter_factor: f64,
}Expand description
Retry policy configuration
Implements exponential backoff with jitter to prevent thundering herd.
Fields§
§initial_delay: DurationInitial retry delay
max_delay: DurationMaximum retry delay (caps exponential growth)
max_attempts: u32Maximum number of retry attempts
backoff_multiplier: f64Exponential backoff base (typically 2.0)
jitter_factor: f64Jitter factor (0.0 to 1.0) to randomize delays
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn new(
initial_delay: Duration,
max_delay: Duration,
max_attempts: u32,
backoff_multiplier: f64,
) -> RetryPolicy
pub fn new( initial_delay: Duration, max_delay: Duration, max_attempts: u32, backoff_multiplier: f64, ) -> RetryPolicy
Create a new retry policy with custom settings
Sourcepub fn transient() -> RetryPolicy
pub fn transient() -> RetryPolicy
Create a policy for transient errors (aggressive retries)
Sourcepub fn severe() -> RetryPolicy
pub fn severe() -> RetryPolicy
Create a policy for severe errors (conservative retries)
Sourcepub fn delay_for_attempt(&self, attempt: u32) -> Duration
pub fn delay_for_attempt(&self, attempt: u32) -> Duration
Calculate delay for a given attempt number
Uses exponential backoff with jitter: delay = base * multiplier^attempt + random_jitter
Sourcepub fn should_retry(&self, attempt: u32) -> bool
pub fn should_retry(&self, attempt: u32) -> bool
Check if we should retry based on attempt count
Trait Implementations§
Source§impl Clone for RetryPolicy
impl Clone for RetryPolicy
Source§fn clone(&self) -> RetryPolicy
fn clone(&self) -> RetryPolicy
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RetryPolicy
impl Debug for RetryPolicy
Source§impl Default for RetryPolicy
impl Default for RetryPolicy
Source§fn default() -> RetryPolicy
fn default() -> RetryPolicy
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for RetryPolicy
impl RefUnwindSafe for RetryPolicy
impl Send for RetryPolicy
impl Sync for RetryPolicy
impl Unpin for RetryPolicy
impl UnsafeUnpin for RetryPolicy
impl UnwindSafe for RetryPolicy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more