pub trait RetryPolicy: Sized {
type E: Error;
// Required method
fn next_delay(
&self,
context: &RetryContext<'_, Self::E>,
) -> Option<Duration>;
// Provided methods
fn with_max_attempts(
self,
max_attempts: u32,
) -> MaxAttemptsRetryPolicy<Self> { ... }
fn with_max_total_delay(
self,
max_total_delay: Duration,
) -> MaxTotalDelayRetryPolicy<Self> { ... }
fn with_max_jitter(self, max_jitter: Duration) -> JitteredRetryPolicy<Self> { ... }
fn skip_retry_on_error<F>(self, function: F) -> FilteredRetryPolicy<Self, F>
where F: 'static + Fn(&Self::E) -> bool { ... }
}Expand description
Provides the logic for how and when to perform retries.
Required Associated Types§
Required Methods§
Sourcefn next_delay(&self, context: &RetryContext<'_, Self::E>) -> Option<Duration>
fn next_delay(&self, context: &RetryContext<'_, Self::E>) -> Option<Duration>
Returns the duration to wait before trying the next attempt.
context represents the context of a retry operation.
If None is returned then no further retry attempt is made.
Provided Methods§
Sourcefn with_max_attempts(self, max_attempts: u32) -> MaxAttemptsRetryPolicy<Self>
fn with_max_attempts(self, max_attempts: u32) -> MaxAttemptsRetryPolicy<Self>
Returns a new RetryPolicy that respects the given maximum attempts.
Sourcefn with_max_total_delay(
self,
max_total_delay: Duration,
) -> MaxTotalDelayRetryPolicy<Self>
fn with_max_total_delay( self, max_total_delay: Duration, ) -> MaxTotalDelayRetryPolicy<Self>
Returns a new RetryPolicy that respects the given total delay.
Sourcefn with_max_jitter(self, max_jitter: Duration) -> JitteredRetryPolicy<Self>
fn with_max_jitter(self, max_jitter: Duration) -> JitteredRetryPolicy<Self>
Returns a new RetryPolicy that adds jitter(random delay) to underlying policy.
Sourcefn skip_retry_on_error<F>(self, function: F) -> FilteredRetryPolicy<Self, F>
fn skip_retry_on_error<F>(self, function: F) -> FilteredRetryPolicy<Self, F>
Skips retrying on errors that evaluate to true after applying function.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.