Skip to main content

RetryStrategy

Struct RetryStrategy 

Source
pub struct RetryStrategy { /* private fields */ }
Expand description

Retry strategy.

Implementations§

Source§

impl RetryStrategy

Source

pub fn new(config: RetryConfig) -> Self

Creates a new retry strategy with the given configuration.

Source

pub fn default_strategy() -> Self

Creates a retry strategy with default configuration.

Source

pub fn should_retry(&self, error: &Error, attempt: u32) -> bool

Determines whether an error should be retried.

§Arguments
  • error - The error to evaluate.
  • attempt - The current retry attempt number (1-based).
§Returns

true if the error should be retried, false otherwise.

Source

pub fn calculate_delay(&self, attempt: u32, error: &Error) -> Duration

Calculates the retry delay based on strategy type and attempt number.

§Arguments
  • attempt - The current retry attempt number (1-based).
  • error - The error that triggered the retry.
§Returns

The calculated delay duration before the next retry.

Source

pub fn is_server_error(msg: &str) -> bool

Checks if the message indicates a server error (5xx).

Uses word boundary matching to avoid false positives like “order_id: 15001234” being misidentified as containing a 500 error.

§Arguments
  • msg - The error message to check.
§Returns

true if the message indicates a server error, false otherwise.

§Example
use ccxt_core::retry_strategy::RetryStrategy;

// True positives
assert!(RetryStrategy::is_server_error("500 Internal Server Error"));
assert!(RetryStrategy::is_server_error("HTTP 502 Bad Gateway"));

// False positives avoided
assert!(!RetryStrategy::is_server_error("order_id: 15001234"));
assert!(!RetryStrategy::is_server_error("amount: 5000"));
Source

pub fn is_server_error_code(status: u16) -> bool

Checks if an HTTP status code indicates a server error (5xx).

Server errors are HTTP status codes in the range 500-599.

§Arguments
  • status - The HTTP status code to check.
§Returns

true if the status code is in the 500-599 range, false otherwise.

§Example
use ccxt_core::retry_strategy::RetryStrategy;

assert!(RetryStrategy::is_server_error_code(500));
assert!(RetryStrategy::is_server_error_code(502));
assert!(RetryStrategy::is_server_error_code(503));
assert!(RetryStrategy::is_server_error_code(504));
assert!(RetryStrategy::is_server_error_code(599));

assert!(!RetryStrategy::is_server_error_code(200));
assert!(!RetryStrategy::is_server_error_code(400));
assert!(!RetryStrategy::is_server_error_code(404));
assert!(!RetryStrategy::is_server_error_code(499));
assert!(!RetryStrategy::is_server_error_code(600));
Source

pub fn is_server_error_message(msg: &str) -> bool

Checks if a message indicates a server error using word boundary matching.

This method uses regex with word boundaries to precisely detect server error patterns without false positives from numbers that happen to contain 500, 502, etc.

§Arguments
  • msg - The error message to check.
§Returns

true if the message matches server error patterns, false otherwise.

§Patterns Matched
  • Status codes: 500, 502, 503, 504 (as standalone words)
  • Phrases: “internal server error”, “bad gateway”, “service unavailable”, “gateway timeout”
§Example
use ccxt_core::retry_strategy::RetryStrategy;

// Matches server error patterns
assert!(RetryStrategy::is_server_error_message("500 Internal Server Error"));
assert!(RetryStrategy::is_server_error_message("Error: 502"));
assert!(RetryStrategy::is_server_error_message("Service Unavailable"));

// Does NOT match numbers containing 500, 502, etc.
assert!(!RetryStrategy::is_server_error_message("order_id: 15001234"));
assert!(!RetryStrategy::is_server_error_message("balance: 5020.50"));
assert!(!RetryStrategy::is_server_error_message("id=25030"));
Source

pub fn config(&self) -> &RetryConfig

Returns a reference to the retry configuration.

Source

pub fn max_retries(&self) -> u32

Returns the maximum number of retries.

Trait Implementations§

Source§

impl Clone for RetryStrategy

Source§

fn clone(&self) -> RetryStrategy

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RetryStrategy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more