1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! # do-over
//!
//! An async-first resilience and transient fault handling library for Rust,
//! inspired by the .NET Polly library.
//!
//! ## Overview
//!
//! `do-over` provides a set of resilience policies that can be used to make your
//! applications more robust when dealing with transient failures, network issues,
//! and other common problems in distributed systems.
//!
//! ## Policies
//!
//! - [`retry::RetryPolicy`] - Retry failed operations with configurable backoff
//! - [`circuit_breaker::CircuitBreaker`] - Prevent cascading failures
//! - [`timeout::TimeoutPolicy`] - Time-bound operations
//! - [`bulkhead::Bulkhead`] - Limit concurrent executions
//! - [`rate_limit::RateLimiter`] - Token bucket rate limiting
//! - [`hedge::Hedge`] - Hedged requests for latency reduction
//! - [`fallback::FallbackExt`] - Return default values on failure
//! - [`cache::TypedCache`] - Cache successful results
//! - [`wrap::Wrap`] - Compose multiple policies together
//!
//! ## Utilities
//!
//! - [`context::Context`] - Pass metadata through policy execution
//!
//! ## Quick Start
//!
//! ```rust
//! use do_over::{policy::Policy, retry::RetryPolicy, timeout::TimeoutPolicy, wrap::Wrap, error::DoOverError};
//! use std::time::Duration;
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! // Create a policy that retries 3 times with a 5s timeout per attempt
//! let policy = Wrap::new(
//! RetryPolicy::fixed(3, Duration::from_millis(100)),
//! TimeoutPolicy::new(Duration::from_secs(5)),
//! );
//!
//! // Execute your operation with resilience
//! let result: Result<&str, DoOverError<&str>> = policy.execute(|| async {
//! Ok("success")
//! }).await;
//! # Ok(())
//! # }
//! ```
//!
//! ## Policy Composition
//!
//! Policies can be composed using [`wrap::Wrap`]. The recommended ordering
//! (from outer to inner) is:
//!
//! 1. Bulkhead - Limit concurrency first
//! 2. Circuit Breaker - Fast-fail if too many errors
//! 3. Rate Limiter - Throttle requests
//! 4. Retry - Handle transient failures
//! 5. Timeout - Bound individual attempts
//!
//! ## Feature Flags
//!
//! - `http` - Enables reqwest integration
//! - `metrics-prometheus` - Prometheus metrics
//! - `metrics-otel` - OpenTelemetry metrics