pub struct RetryPolicy { /* private fields */ }Expand description
Policy-driven retry configuration.
Controls which requests are retried, how many times, and with what backoff strategy. Retries are opt-in: the default policy disables retries.
§Examples
use std::time::Duration;
use eggfetch_core::RetryPolicy;
let policy = RetryPolicy::builder()
.max_attempts(3)
.backoff_factor(0.2)
.retry_status(429)
.retry_status(503)
.build();Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn builder() -> RetryPolicyBuilder
pub fn builder() -> RetryPolicyBuilder
Create a new retry policy builder.
Sourcepub fn max_attempts(&self) -> usize
pub fn max_attempts(&self) -> usize
Returns the maximum number of total attempts.
Sourcepub fn max_elapsed(&self) -> Option<Duration>
pub fn max_elapsed(&self) -> Option<Duration>
Returns the maximum total elapsed time.
Sourcepub fn backoff(&self) -> &BackoffPolicy
pub fn backoff(&self) -> &BackoffPolicy
Returns a reference to the backoff policy.
Sourcepub fn method_policy(&self) -> &MethodPolicy
pub fn method_policy(&self) -> &MethodPolicy
Returns a reference to the method policy.
Sourcepub fn status_policy(&self) -> &StatusPolicy
pub fn status_policy(&self) -> &StatusPolicy
Returns a reference to the status policy.
Sourcepub fn respect_retry_after(&self) -> bool
pub fn respect_retry_after(&self) -> bool
Returns whether Retry-After headers are respected.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Returns true if retries are effectively enabled (max_attempts > 1).
Sourcepub fn is_method_retryable(&self, method: &Method) -> bool
pub fn is_method_retryable(&self, method: &Method) -> bool
Returns true if the given method is eligible for retry.
Sourcepub fn is_status_retryable(&self, status: u16) -> bool
pub fn is_status_retryable(&self, status: u16) -> bool
Returns true if the given status code is eligible for retry.
Sourcepub fn is_error_retryable(error: &Error) -> bool
pub fn is_error_retryable(error: &Error) -> bool
Returns true if the given error is eligible for retry.
Sourcepub fn backoff_delay(&self, attempt: usize) -> Option<Duration>
pub fn backoff_delay(&self, attempt: usize) -> Option<Duration>
Compute the backoff delay for the given attempt number (1-indexed).
Returns None if no delay is needed (attempt 1).
Sourcepub fn retry_after_delay(&self, retry_after: &str) -> Option<Duration>
pub fn retry_after_delay(&self, retry_after: &str) -> Option<Duration>
Compute the delay after receiving a Retry-After header value.
Parses Retry-After as either a number of seconds or an HTTP-date.
Returns None if parsing fails, if a past HTTP-date is supplied
(the header carries no useful information), or if the value
exceeds the backoff cap.
Sourcepub fn check_body_replayable(body: &RequestBody) -> ReplayCheck
pub fn check_body_replayable(body: &RequestBody) -> ReplayCheck
Check if a request body is replayable for retry.
Returns ReplayCheck::Replayable if the body can be replayed,
or ReplayCheck::NotReplayable if the body is a live stream.