Skip to main content

loop_retry/
traits.rs

1//! Trait for classifying retryable errors.
2
3/// Trait for errors that can be classified as retryable.
4pub trait IsRetryable {
5    /// Returns true if the operation should be retried.
6    fn is_retryable(&self) -> bool;
7}
8
9// Implement for common error types
10impl IsRetryable for std::io::Error {
11    fn is_retryable(&self) -> bool {
12        matches!(
13            self.kind(),
14            std::io::ErrorKind::ConnectionRefused
15                | std::io::ErrorKind::ConnectionReset
16                | std::io::ErrorKind::ConnectionAborted
17                | std::io::ErrorKind::TimedOut
18                | std::io::ErrorKind::WouldBlock
19                | std::io::ErrorKind::BrokenPipe
20        )
21    }
22}
23
24impl IsRetryable for std::net::AddrParseError {
25    fn is_retryable(&self) -> bool {
26        false
27    }
28}