pub struct RetryEngine { /* private fields */ }Expand description
The one shared retry engine every retrying surface instantiates
(RetryClass::engine). It owns the universal rules so no surface re-derives
them: exponential backoff with full jitter, honoring a server backoff
signal (Retry-After / 429 / 503) as a floor, and a bounded give-up after
max_retries — never an unbounded hot loop.
The engine is a pure state machine over the attempt counter and the jitter
source: RetryEngine::next_backoff computes the wait and the give-up without
sleeping, so backoff discipline is a deterministic unit test. Callers perform
the wait through a Sleeper (real in production, a no-op recorder in tests).
Implementations§
Source§impl RetryEngine
impl RetryEngine
Sourcepub fn new(class: RetryClass) -> Self
pub fn new(class: RetryClass) -> Self
A production engine for class, full-jitter seeded from the wall clock.
Sourcepub fn deterministic(class: RetryClass, fraction: f64) -> Self
pub fn deterministic(class: RetryClass, fraction: f64) -> Self
A deterministic engine that always jitters by the fixed fraction
(clamped to [0, 1]) — for tests that assert exact backoff values.
Sourcepub fn seeded(class: RetryClass, seed: u64) -> Self
pub fn seeded(class: RetryClass, seed: u64) -> Self
A production-shaped engine (full jitter) with a fixed seed — for tests that assert the spread property of full jitter deterministically.
Sourcepub fn class(&self) -> RetryClass
pub fn class(&self) -> RetryClass
The class this engine instantiates.
Sourcepub fn policy(&self) -> RetryPolicy
pub fn policy(&self) -> RetryPolicy
The policy bounds this engine enforces.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the attempt counter after real progress, so a long-lived transfer’s backoff does not ratchet across independent stalls (resume-first: each resumed window earns a fresh budget).
Sourcepub fn next_backoff(
&mut self,
server_backoff: Option<Duration>,
) -> RetryDecision
pub fn next_backoff( &mut self, server_backoff: Option<Duration>, ) -> RetryDecision
Decide the next action after a failure, folding in an optional server
backoff hint (Retry-After / 429 / 503).
Returns RetryDecision::GiveUp once the bounded budget is spent (so no
configuration can hot-loop). Otherwise the wait is full jitter over the
ceiling — a uniform draw in [0, ceiling] — reconciled with the server hint
as a floor (Retry-After is honored even when it exceeds the jittered
value). The ceiling itself is bounded by max_delay, so the client-chosen
component of the wait never exceeds the policy cap.
Trait Implementations§
Source§impl Clone for RetryEngine
impl Clone for RetryEngine
Source§fn clone(&self) -> RetryEngine
fn clone(&self) -> RetryEngine
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for RetryEngine
impl RefUnwindSafe for RetryEngine
impl Send for RetryEngine
impl Sync for RetryEngine
impl Unpin for RetryEngine
impl UnsafeUnpin for RetryEngine
impl UnwindSafe for RetryEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
§unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
Arc<> Read more§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more