Skip to main content

CasBuilder

Struct CasBuilder 

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

Builder for CasExecutor.

Implementations§

Source§

impl<T, E> CasBuilder<T, E>

Source

pub fn new() -> Self

Creates a builder with default retry options.

§Returns

A CasBuilder using RetryOptions::default.

Source

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

Replaces builder settings from an existing retry option snapshot.

§Parameters
  • options: Retry option snapshot to install.
§Returns

The updated builder.

Source

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

Sets the maximum total attempts.

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

The updated builder.

Source

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

Sets the maximum retries after the initial attempt.

§Parameters
  • max_retries: Maximum retries after the first attempt.
§Returns

The updated builder.

Source

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

Sets the maximum cumulative user operation elapsed-time budget.

§Parameters
  • max_operation_elapsed: Optional cumulative user operation time budget.
§Returns

The updated builder.

Source

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

Sets the maximum monotonic elapsed-time budget for the whole retry flow.

§Parameters
  • max_total_elapsed: Optional total retry-flow time budget.
§Returns

The updated builder.

Source

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

Sets the base retry delay strategy.

§Parameters
  • delay: Delay strategy used between failed attempts.
§Returns

The updated builder.

Source

pub fn no_delay(self) -> Self

Uses immediate retries with no sleep.

§Returns

The updated builder.

Source

pub fn fixed_delay(self, delay: Duration) -> Self

Uses one fixed retry delay.

§Parameters
  • delay: Delay slept before each retry.
§Returns

The updated builder.

Source

pub fn random_delay(self, min: Duration, max: Duration) -> Self

Uses one random retry delay range.

§Parameters
  • min: Inclusive minimum delay.
  • max: Inclusive maximum delay.
§Returns

The updated builder.

Source

pub fn exponential_backoff(self, initial: Duration, max: Duration) -> Self

Uses exponential backoff with multiplier 2.0.

§Parameters
  • initial: Initial retry delay.
  • max: Maximum retry delay.
§Returns

The updated builder.

Source

pub fn exponential_backoff_with_multiplier( self, initial: Duration, max: Duration, multiplier: f64, ) -> Self

Uses exponential backoff with a custom multiplier.

§Parameters
  • initial: Initial retry delay.
  • max: Maximum retry delay.
  • multiplier: Multiplier applied after each failed attempt.
§Returns

The updated builder.

Source

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

Sets the jitter strategy.

§Parameters
  • jitter: Jitter strategy applied to retry delays.
§Returns

The updated builder.

Source

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

Sets relative jitter by factor.

§Parameters
  • factor: Relative jitter factor in [0.0, 1.0].
§Returns

The updated builder.

Source

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

Sets the async per-attempt timeout.

§Parameters
  • attempt_timeout: Timeout applied to each async CAS attempt.
§Returns

The updated builder.

Source

pub fn retry_on_timeout(self) -> Self

Retries attempts that exceed the configured timeout.

§Returns

The updated builder.

Source

pub fn abort_on_timeout(self) -> Self

Aborts the CAS flow when one attempt exceeds the timeout.

§Returns

The updated builder.

Source

pub fn strategy(self, strategy: CasStrategy) -> Self

Applies a built-in CAS strategy to this builder.

§Parameters
  • strategy: Strategy profile to install.
§Returns

The updated builder.

Source

pub fn observability(self, observability: CasObservabilityConfig) -> Self

Installs observability configuration.

§Parameters
  • observability: Observability settings to use.
§Returns

The updated builder.

Source

pub fn alert_on_contention(self, thresholds: ContentionThresholds) -> Self

Enables contention alerting with the supplied thresholds.

§Parameters
  • thresholds: Thresholds used to classify hot contention.
§Returns

The updated builder.

Source

pub fn isolate_listener_panics(self) -> Self

Enables retry-layer listener panic isolation.

§Returns

The updated builder.

Source

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

Builds one executor after validating the settings.

§Returns

A validated CasExecutor.

§Errors

Returns RetryConfigError when the configured retry settings are invalid.

Source

pub fn build_contention_adaptive( self, ) -> Result<CasExecutor<T, E>, RetryConfigError>

Builds one executor with the contention-adaptive strategy.

§Returns

A configured CasExecutor suitable for contended writers.

Source

pub fn build_latency_first(self) -> Result<CasExecutor<T, E>, RetryConfigError>

Builds one executor with the latency-first strategy.

§Returns

A configured CasExecutor optimized for low latency.

Source

pub fn build_reliability_first( self, ) -> Result<CasExecutor<T, E>, RetryConfigError>

Builds one executor with the reliability-first strategy.

§Returns

A configured CasExecutor optimized for long retry windows.

Trait Implementations§

Source§

impl<T, E> Default for CasBuilder<T, E>

Source§

fn default() -> Self

Creates a default CAS builder.

§Returns

A builder equivalent to CasBuilder::new.

Auto Trait Implementations§

§

impl<T, E> Freeze for CasBuilder<T, E>

§

impl<T, E> RefUnwindSafe for CasBuilder<T, E>

§

impl<T, E> Send for CasBuilder<T, E>

§

impl<T, E> Sync for CasBuilder<T, E>

§

impl<T, E> Unpin for CasBuilder<T, E>

§

impl<T, E> UnsafeUnpin for CasBuilder<T, E>

§

impl<T, E> UnwindSafe for CasBuilder<T, E>

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

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.