pub struct RetryOutcome<'a> { /* private fields */ }Expand description
What one execution of a request produced, handed to RetryPolicy::retry so it can decide
whether to retry: the [http::Request] that was sent, and either the raw [http::Response] the inner
backend returned (any status — success or error) or the TransportError it failed with (DNS,
connect, timeout, …).
The policy inspects it to make its decision: RetryOutcome::status exposes the response status
(e.g. retry on 429/5xx), RetryOutcome::transport_error the transport failure (e.g. retry
on a timeout), RetryOutcome::method the request method, RetryOutcome::retry_after the
server’s requested delay, and RetryOutcome::is_transient applies the runtime’s own
classifier as a sensible default.
Implementations§
Source§impl<'a> RetryOutcome<'a>
impl<'a> RetryOutcome<'a>
Sourcepub fn new(
request: &'a Request<HttpBody>,
result: Result<&'a Response<HttpBody>, &'a TransportError>,
) -> Self
pub fn new( request: &'a Request<HttpBody>, result: Result<&'a Response<HttpBody>, &'a TransportError>, ) -> Self
The outcome of sending request: Ok with the response the inner backend returned, or
Err with the transport failure it reported.
Sourcepub fn request(&self) -> &'a Request<HttpBody>
pub fn request(&self) -> &'a Request<HttpBody>
The request this attempt sent, as the next attempt would resend it.
Sourcepub fn response(&self) -> Option<&'a Response<HttpBody>>
pub fn response(&self) -> Option<&'a Response<HttpBody>>
The response, if the attempt produced one (any status). None on a transport failure.
Sourcepub fn transport_error(&self) -> Option<&'a TransportError>
pub fn transport_error(&self) -> Option<&'a TransportError>
The transport failure, if the attempt failed before producing a response. None otherwise.
Sourcepub fn status(&self) -> Option<StatusCode>
pub fn status(&self) -> Option<StatusCode>
The response status, if any. None on a transport failure — a policy keying purely on
status can treat that as “retry” or “stop” as it sees fit.
Sourcepub fn result(&self) -> Result<&'a Response<HttpBody>, &'a TransportError>
pub fn result(&self) -> Result<&'a Response<HttpBody>, &'a TransportError>
The outcome as a Result, mirroring what the inner backend returned.
Sourcepub fn is_idempotent(&self) -> bool
pub fn is_idempotent(&self) -> bool
Whether the request is safe to send again: its method is idempotent by RFC 9110 §9.2.2
(GET, HEAD, OPTIONS, TRACE, PUT, DELETE), or it carries an Idempotency-Key
header, which marks a request of any method as one the server applies at most once.
Sourcepub fn is_transient(&self) -> bool
pub fn is_transient(&self) -> bool
Whether the outcome is worth retrying by the runtime’s default classifier: the request
is idempotent, and the failure is one super::Error::is_transient
calls transient for the error this outcome becomes. A 429 or 5xx response is transient.
A transport failure is transient when the class its TransportError carries is: a
timeout, a failed connection, or an interrupted body is, and a redirect-policy, protocol,
or request-kind failure (super::RequestError::Other) is not. super::ReqwestBackend
classifies as super::TransportError::from_reqwest documents, so on wasm32 a failed connection
is request-kind there. A POST or PATCH without an Idempotency-Key is never
transient here, since the server may already have applied it. Policies are free to ignore
this and key on Self::status / Self::transport_error directly.
Sourcepub fn retry_after(&self, now: SystemTime) -> Option<Duration>
pub fn retry_after(&self, now: SystemTime) -> Option<Duration>
The delay the response’s Retry-After header asks for, measured from now: its
delay-seconds, or the time from now until its HTTP-date (zero once that date has passed).
All three HTTP-date forms RFC 9110 §5.6.7 requires a recipient to accept are read: the
IMF-fixdate, the obsolete RFC 850 form, and the asctime form. None on a transport failure,
and for a response with no Retry-After, more than one, or one that does not parse.
now is the caller’s clock (SystemTime::now() off wasm32); the runtime reads none.
Sourcepub fn backoff(
&self,
attempt: u32,
base: Duration,
max: Duration,
now: SystemTime,
) -> Duration
pub fn backoff( &self, attempt: u32, base: Duration, max: Duration, now: SystemTime, ) -> Duration
The wait before the next attempt: exponential_backoff of attempt, base and max,
raised to the response’s Self::retry_after delay where that is longer. The server’s
delay is a floor the backoff’s max does not cap; a policy unwilling to wait that long
stops instead of retrying.
Trait Implementations§
Source§impl<'a> Clone for RetryOutcome<'a>
impl<'a> Clone for RetryOutcome<'a>
Source§fn clone(&self) -> RetryOutcome<'a>
fn clone(&self) -> RetryOutcome<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<'a> Copy for RetryOutcome<'a>
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for RetryOutcome<'a>
impl<'a> !UnwindSafe for RetryOutcome<'a>
impl<'a> Freeze for RetryOutcome<'a>
impl<'a> Send for RetryOutcome<'a>
impl<'a> Sync for RetryOutcome<'a>
impl<'a> Unpin for RetryOutcome<'a>
impl<'a> UnsafeUnpin for RetryOutcome<'a>
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