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
84
85
86
87
88
89
90
//! Composable resilience and fault-tolerance middleware for Tower services.
//!
//! `tower-resilience` provides a collection of resilience patterns that can be composed
//! together to build robust distributed systems. Each pattern is available as both an
//! individual crate and as a feature in this meta-crate.
//!
//! # Patterns
//!
//! - **Circuit Breaker** (`circuitbreaker` feature): Prevents cascading failures by
//! temporarily blocking calls to failing services
//! - **Bulkhead** (`bulkhead` feature): Isolates resources by limiting concurrent calls
//! - **Time Limiter** (`timelimiter` feature): Advanced timeout handling with event system
//! - **Cache** (`cache` feature): Response memoization with LRU eviction and TTL
//! - **Retry** (`retry` feature): Enhanced retry with flexible backoff strategies
//!
//! # Usage
//!
//! Enable specific patterns via features:
//!
//! ```toml
//! [dependencies]
//! tower-resilience = { version = "0.1", features = ["circuitbreaker", "bulkhead"] }
//! ```
//!
//! Or enable all patterns:
//!
//! ```toml
//! [dependencies]
//! tower-resilience = { version = "0.1", features = ["full"] }
//! ```
//!
//! # Example
//!
//! ```rust,no_run
//! # #[cfg(all(feature = "circuitbreaker", feature = "bulkhead"))]
//! # {
//! use tower::ServiceBuilder;
//! use tower_resilience::{circuitbreaker::CircuitBreakerConfig, bulkhead::BulkheadConfig};
//!
//! # async fn example() {
//! # let my_service = tower::service_fn(|_req: ()| async { Ok::<_, std::io::Error>(()) });
//! // Build bulkhead layer (implements Tower Layer trait)
//! let bulkhead_layer = BulkheadConfig::builder()
//! .max_concurrent_calls(10)
//! .build();
//!
//! let service = ServiceBuilder::new()
//! .layer(bulkhead_layer)
//! .service(my_service);
//!
//! // Wrap with circuit breaker (uses manual .layer() method)
//! let cb_layer = CircuitBreakerConfig::<(), std::io::Error>::builder()
//! .failure_rate_threshold(0.5)
//! .sliding_window_size(100)
//! .build();
//!
//! let _service = cb_layer.layer::<_, ()>(service);
//! # }
//! # }
//! ```
//!
//! # Individual Crates
//!
//! Each pattern is also available as a standalone crate for minimal dependencies:
//!
//! - `tower-circuitbreaker`
//! - `tower-bulkhead`
//! - `tower-timelimiter`
//! - `tower-cache`
//! - `tower-retry-plus`
//! - `tower-resilience-core` (shared infrastructure)
// Re-export core (always available)
pub use tower_resilience_core as core;
// Re-export patterns based on features
pub use tower_resilience_circuitbreaker as circuitbreaker;
pub use tower_resilience_bulkhead as bulkhead;
pub use tower_resilience_timelimiter as timelimiter;
pub use tower_resilience_cache as cache;
pub use tower_resilience_retry as retry;