Trait RetryPolicy

Source
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§

Source

type E: Error

The error type returned by the operation in retry.

Required Methods§

Source

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§

Source

fn with_max_attempts(self, max_attempts: u32) -> MaxAttemptsRetryPolicy<Self>

Returns a new RetryPolicy that respects the given maximum attempts.

Source

fn with_max_total_delay( self, max_total_delay: Duration, ) -> MaxTotalDelayRetryPolicy<Self>

Returns a new RetryPolicy that respects the given total delay.

Source

fn with_max_jitter(self, max_jitter: Duration) -> JitteredRetryPolicy<Self>

Returns a new RetryPolicy that adds jitter(random delay) to underlying policy.

Source

fn skip_retry_on_error<F>(self, function: F) -> FilteredRetryPolicy<Self, F>
where F: 'static + Fn(&Self::E) -> bool,

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.

Implementors§