Skip to main content

RetryExecutorBuilder

Struct RetryExecutorBuilder 

Source
pub struct RetryExecutorBuilder<E = BoxError> { /* private fields */ }
Expand description

Builder for RetryExecutor.

The generic parameter E is the application error type that the resulting executor will classify. If no classifier is provided, the built executor retries every application error until limits stop execution.

Implementations§

Source§

impl<E> RetryExecutorBuilder<E>

Source

pub fn new() -> Self

Creates a builder with default options and a retry-all classifier.

§Parameters

This function has no parameters.

§Returns

A builder with RetryOptions::default and no listeners.

Source

pub fn options(self, options: RetryOptions) -> Self

Replaces all options with an existing option snapshot.

§Parameters
  • options: Retry options to install in the builder.
§Returns

The updated builder.

§Errors

This method does not return errors immediately. Validation occurs in RetryExecutorBuilder::build.

Source

pub fn max_attempts(self, max_attempts: u32) -> Self

Sets the maximum number of attempts.

§Parameters
  • max_attempts: Maximum attempts, including the initial attempt.
§Returns

The updated builder.

§Errors

This method records a configuration error when max_attempts is zero. The error is returned later by RetryExecutorBuilder::build.

Source

pub fn max_elapsed(self, max_elapsed: Option<Duration>) -> Self

Sets the maximum total elapsed time.

§Parameters
  • max_elapsed: Optional total elapsed-time budget for the whole retry execution. None means unlimited.
§Returns

The updated builder.

§Errors

This method does not return errors.

Source

pub fn delay(self, delay: RetryDelay) -> Self

Sets the base delay strategy.

§Parameters
  • delay: Base delay strategy to use between attempts.
§Returns

The updated builder.

§Errors

This method does not return errors immediately. RetryDelay validation occurs in RetryExecutorBuilder::build.

Source

pub fn jitter(self, jitter: RetryJitter) -> Self

Sets the jitter strategy.

§Parameters
  • jitter: RetryJitter strategy to apply to each base delay.
§Returns

The updated builder.

§Errors

This method does not return errors immediately. RetryJitter validation occurs in RetryExecutorBuilder::build.

Source

pub fn jitter_factor(self, factor: f64) -> Self

Sets the jitter strategy from a relative factor.

§Parameters
  • factor: Relative jitter range. Valid values are finite and within [0.0, 1.0].
§Returns

The updated builder.

§Errors

This method does not return errors immediately. Factor validation occurs in RetryExecutorBuilder::build.

Source

pub fn retry_if<P>(self, retry_tester: P) -> Self
where P: BiPredicate<E, RetryAttemptContext> + Send + Sync + 'static,

Uses a boolean retry tester where true means retry.

§Parameters
§Returns

The updated builder.

§Errors

This method does not return errors.

§Panics

The built executor propagates any panic raised by retry_tester.

Source

pub fn retry_decide<B>(self, decider: B) -> Self

Chooses RetryDecision for each failed attempt from the error and RetryAttemptContext.

§Parameters
  • decider: Any BiFunction over the application error and RetryAttemptContext (including closures); it is converted with BiFunction::into_arc. The decider itself must be Send + Sync + 'static; the application error type E is not required to be 'static. If type inference fails for a closure, annotate parameters (for example |e: &E, ctx: &RetryAttemptContext|).
§Returns

The updated builder.

§Errors

This method does not return errors.

§Panics

The built executor propagates any panic raised by decider.

Source

pub fn on_retry<F>(self, listener: F) -> Self
where F: Fn(&RetryContext, &RetryAttemptFailure<E>) + Send + Sync + 'static,

Registers a listener invoked before retry sleep.

§Parameters
§Returns

The updated builder.

§Errors

This method does not return errors.

§Panics

The built executor propagates any panic raised by listener.

Source

pub fn on_success<F>(self, listener: F) -> Self
where F: Fn(&RetrySuccessContext) + Send + Sync + 'static,

Registers a listener invoked when the operation succeeds.

§Parameters
  • listener: Callback invoked with a RetrySuccessContext when the operation eventually succeeds.
§Returns

The updated builder.

§Errors

This method does not return errors.

§Panics

The built executor propagates any panic raised by listener.

Source

pub fn on_failure<F>(self, listener: F) -> Self
where F: Fn(&RetryFailureContext, &Option<RetryAttemptFailure<E>>) + Send + Sync + 'static,

Registers a listener invoked when retry limits are exhausted.

§Parameters
  • listener: Callback invoked with RetryFailureContext metadata plus Option<RetryAttemptFailure<E>> when retry limits stop execution.
§Returns

The updated builder.

§Errors

This method does not return errors.

§Panics

The built executor propagates any panic raised by listener.

Source

pub fn on_abort<F>(self, listener: F) -> Self
where F: Fn(&RetryAbortContext, &RetryAttemptFailure<E>) + Send + Sync + 'static,

Registers a listener invoked when the classifier aborts retrying.

§Parameters
  • listener: Callback invoked with RetryAbortContext metadata plus the failure when the classifier aborts retrying.
§Returns

The updated builder.

§Errors

This method does not return errors.

§Panics

The built executor propagates any panic raised by listener.

Source

pub fn build(self) -> Result<RetryExecutor<E>, RetryConfigError>

Builds and validates the executor.

§Parameters

This method has no parameters.

§Returns

A validated RetryExecutor.

§Errors

Returns RetryConfigError when max_attempts was set to zero or when delay or jitter validation fails.

Trait Implementations§

Source§

impl<E> Default for RetryExecutorBuilder<E>

Source§

fn default() -> Self

Creates a default retry executor builder.

§Parameters

This function has no parameters.

§Returns

A builder equivalent to RetryExecutorBuilder::new.

§Errors

This function does not return errors.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.