pub struct RetryStrategy { /* private fields */ }Expand description
Retry strategy.
Implementations§
Source§impl RetryStrategy
impl RetryStrategy
Sourcepub fn new(config: RetryConfig) -> RetryStrategy
pub fn new(config: RetryConfig) -> RetryStrategy
Creates a new retry strategy with the given configuration.
Sourcepub fn default_strategy() -> RetryStrategy
pub fn default_strategy() -> RetryStrategy
Creates a retry strategy with default configuration.
Sourcepub fn should_retry(&self, error: &Error, attempt: u32) -> bool
pub fn should_retry(&self, error: &Error, attempt: u32) -> bool
Sourcepub fn calculate_delay(&self, attempt: u32, error: &Error) -> Duration
pub fn calculate_delay(&self, attempt: u32, error: &Error) -> Duration
Sourcepub fn is_server_error(msg: &str) -> bool
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"));Sourcepub fn is_server_error_code(status: u16) -> bool
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));Sourcepub fn is_server_error_message(msg: &str) -> bool
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"));Sourcepub fn config(&self) -> &RetryConfig
pub fn config(&self) -> &RetryConfig
Returns a reference to the retry configuration.
Sourcepub fn max_retries(&self) -> u32
pub fn max_retries(&self) -> u32
Returns the maximum number of retries.
Trait Implementations§
Source§impl Clone for RetryStrategy
impl Clone for RetryStrategy
Source§fn clone(&self) -> RetryStrategy
fn clone(&self) -> RetryStrategy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more