RetryStrategy

Enum RetryStrategy 

Source
pub enum RetryStrategy {
    Fixed {
        delay: u64,
    },
    Linear {
        initial: u64,
        increment: u64,
        max_delay: Option<u64>,
    },
    Exponential {
        initial: u64,
        multiplier: f64,
        max_delay: Option<u64>,
    },
    Polynomial {
        initial: u64,
        power: f64,
        max_delay: Option<u64>,
    },
    Fibonacci {
        initial: u64,
        max_delay: Option<u64>,
    },
    DecorrelatedJitter {
        base: u64,
        max_delay: u64,
    },
    FullJitter {
        initial: u64,
        multiplier: f64,
        max_delay: Option<u64>,
    },
    EqualJitter {
        initial: u64,
        multiplier: f64,
        max_delay: Option<u64>,
    },
    Custom {
        delays: Vec<u64>,
        fallback: u64,
    },
    Immediate,
}
Expand description

Retry strategy configuration

Variants§

§

Fixed

Fixed delay between retries

Fields

§delay: u64

Delay in seconds

§

Linear

Linear backoff (delay increases linearly)

Fields

§initial: u64

Initial delay in seconds

§increment: u64

Increment per retry in seconds

§max_delay: Option<u64>

Maximum delay in seconds

§

Exponential

Exponential backoff (delay doubles each retry)

Fields

§initial: u64

Initial delay in seconds

§multiplier: f64

Multiplier (default 2.0)

§max_delay: Option<u64>

Maximum delay in seconds

§

Polynomial

Polynomial backoff (delay = initial * retry^power)

Fields

§initial: u64

Initial delay in seconds

§power: f64

Power (exponent)

§max_delay: Option<u64>

Maximum delay in seconds

§

Fibonacci

Fibonacci backoff (delays follow Fibonacci sequence)

Fields

§initial: u64

Initial delay in seconds (F(1))

§max_delay: Option<u64>

Maximum delay in seconds

§

DecorrelatedJitter

Decorrelated jitter (AWS recommended for distributed systems) delay = random(base, previous_delay * 3)

Fields

§base: u64

Base delay in seconds

§max_delay: u64

Maximum delay in seconds

§

FullJitter

Full jitter (random between 0 and exponential delay)

Fields

§initial: u64

Initial delay in seconds

§multiplier: f64

Multiplier (default 2.0)

§max_delay: Option<u64>

Maximum delay in seconds

§

EqualJitter

Equal jitter (half fixed, half random)

Fields

§initial: u64

Initial delay in seconds

§multiplier: f64

Multiplier (default 2.0)

§max_delay: Option<u64>

Maximum delay in seconds

§

Custom

Custom delays specified explicitly for each retry

Fields

§delays: Vec<u64>

Delays for each retry attempt

§fallback: u64

Delay to use after all custom delays exhausted

§

Immediate

No delay between retries

Implementations§

Source§

impl RetryStrategy

Source

pub fn fixed(delay: u64) -> Self

Create a fixed delay strategy

Source

pub fn linear(initial: u64, increment: u64) -> Self

Create a linear backoff strategy

Source

pub fn linear_with_max(initial: u64, increment: u64, max_delay: u64) -> Self

Create a linear backoff strategy with max delay

Source

pub fn exponential(initial: u64, multiplier: f64) -> Self

Create an exponential backoff strategy

Source

pub fn exponential_with_max( initial: u64, multiplier: f64, max_delay: u64, ) -> Self

Create an exponential backoff strategy with max delay

Source

pub fn polynomial(initial: u64, power: f64) -> Self

Create a polynomial backoff strategy

Source

pub fn fibonacci(initial: u64) -> Self

Create a Fibonacci backoff strategy

Source

pub fn decorrelated_jitter(base: u64, max_delay: u64) -> Self

Create a decorrelated jitter strategy (AWS recommended)

Source

pub fn full_jitter(initial: u64, multiplier: f64, max_delay: u64) -> Self

Create a full jitter strategy

Source

pub fn equal_jitter(initial: u64, multiplier: f64, max_delay: u64) -> Self

Create an equal jitter strategy

Source

pub fn custom(delays: Vec<u64>, fallback: u64) -> Self

Create a custom delays strategy

Source

pub fn immediate() -> Self

Create an immediate retry strategy (no delay)

Source

pub fn calculate_delay( &self, retry_count: u32, previous_delay: Option<u64>, ) -> u64

Calculate the delay for a given retry attempt

§Arguments
  • retry_count - Current retry attempt (0-based)
  • previous_delay - Previous delay (used by decorrelated jitter)
§Returns

Delay in seconds before the next retry

Source

pub const fn name(&self) -> &'static str

Get the strategy name as a string

Source

pub const fn is_jittered(&self) -> bool

Check if this strategy uses randomness

Trait Implementations§

Source§

impl Clone for RetryStrategy

Source§

fn clone(&self) -> RetryStrategy

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RetryStrategy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RetryStrategy

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for RetryStrategy

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for RetryStrategy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for RetryStrategy

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,