Skip to main content

error_forge/recovery/
mod.rs

1//! Error recovery patterns for handling transient errors
2//!
3//! This module provides various error recovery strategies that can be used to make
4//! applications more resilient to transient failures.
5//!
6//! # Features
7//!
8//! - Backoff strategies for controlling retry timing
9//! - Circuit breaker pattern to prevent cascading failures
10//! - Retry policies for flexible retry behaviors
11//! - `ForgeError`-aware retry executors for sync workloads
12//!
13//! # Examples
14//!
15//! ```
16//! use error_forge::recovery::RetryPolicy;
17//!
18//! let policy = RetryPolicy::new_exponential().with_max_retries(3);
19//!
20//! // The operation must declare its error type so the policy can
21//! // type-check the retry loop. Here we use `std::io::Error`.
22//! let result: Result<(), std::io::Error> = policy.retry(|| Ok(()));
23//! assert!(result.is_ok());
24//! ```
25
26mod backoff;
27mod circuit_breaker;
28mod forge_extensions;
29mod retry;
30
31pub use backoff::{Backoff, ExponentialBackoff, FixedBackoff, LinearBackoff};
32pub use circuit_breaker::{CircuitBreaker, CircuitBreakerConfig, CircuitOpenError, CircuitState};
33pub use forge_extensions::ForgeErrorRecovery;
34pub use retry::{RetryExecutor, RetryPolicy};
35
36/// Result type for recovery operations
37pub type RecoveryResult<T> =
38    std::result::Result<T, Box<dyn std::error::Error + Send + Sync + 'static>>;