TransientError

Trait TransientError 

Source
pub trait TransientError {
    // Required method
    fn is_transient(&self) -> bool;

    // Provided methods
    fn is_permanent(&self) -> bool { ... }
    fn retry_after_hint(&self) -> Option<Duration> { ... }
    fn max_retries_hint(&self) -> Option<u32> { ... }
}
Expand description

Classification of errors as transient or permanent.

Transient errors are temporary failures that may succeed if retried, such as network timeouts, rate limiting, or temporary service unavailability.

This trait enables integration with external retry/circuit-breaker libraries by providing a standard interface for error classification.

§Design Philosophy

error-rail follows the principle of composition over built-in features. Rather than implementing full retry logic, we provide this classification trait that works seamlessly with:

§Examples

§Basic Implementation

use error_rail::traits::TransientError;

#[derive(Debug)]
struct TimeoutError;

impl TransientError for TimeoutError {
    fn is_transient(&self) -> bool {
        true // Timeouts are always transient
    }
}

§With Retry Hint

use error_rail::traits::TransientError;
use core::time::Duration;

#[derive(Debug)]
struct RateLimitError {
    retry_after_secs: u64,
}

impl TransientError for RateLimitError {
    fn is_transient(&self) -> bool {
        true
    }

    fn retry_after_hint(&self) -> Option<Duration> {
        Some(Duration::from_secs(self.retry_after_secs))
    }
}

Required Methods§

Source

fn is_transient(&self) -> bool

Returns true if this error is transient and may succeed on retry.

§Guidelines

Return true for:

  • Network timeouts
  • Rate limiting (HTTP 429)
  • Service temporarily unavailable (HTTP 503)
  • Connection reset/refused (may indicate temporary overload)
  • Deadlock/lock contention errors

Return false for:

  • Authentication/authorization failures
  • Invalid input/validation errors
  • Resource not found
  • Business logic violations

Provided Methods§

Source

fn is_permanent(&self) -> bool

Returns true if this error is permanent and should not be retried.

Default implementation returns !self.is_transient().

Source

fn retry_after_hint(&self) -> Option<Duration>

Optional hint for how long to wait before retrying.

This is useful for rate-limiting errors that include a Retry-After header. External retry libraries can use this to implement respectful backoff.

Returns None by default, indicating no specific wait time is suggested.

Source

fn max_retries_hint(&self) -> Option<u32>

Returns the maximum number of retry attempts for this error.

Returns None by default, indicating no specific limit is suggested. External libraries should use their own default limits.

Implementations on Foreign Types§

Source§

impl TransientError for Error

Available on crate feature std only.

Blanket implementation for standard I/O errors.

Implementors§