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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*******************************************************************************
*
* Copyright (c) 2025 - 2026.
* Haixing Hu, Qubit Co. Ltd.
*
* All rights reserved.
*
******************************************************************************/
//! # Qubit Retry - Retry module
//!
//! A fully-featured, type-safe retry management system, ported from Java's
//! `ltd.qubit.commons.util.retry` package to Rust.
//!
//! ## Design Philosophy
//!
//! ### Core Design Principles
//!
//! 1. **Type Safety First** - Leverage Rust's type system to ensure type safety
//! at compile time
//! 2. **Result Error Handling** - Use Rust's Result type for error handling
//! instead of exceptions
//! 3. **Zero-Cost Abstraction** - Use enums instead of trait objects to avoid
//! dynamic dispatch overhead
//! 4. **Unified Interface** - Provide generic APIs that support all primitive
//! types and custom types
//! 5. **Event-Driven** - Support various event listeners during the retry process
//!
//! ## Module Structure
//!
//! ```text
//! retry/
//! |-- mod.rs # Module entry point, exports public API
//! |-- builder.rs # RetryBuilder struct (core retry builder)
//! |-- config.rs # RetryConfig trait and DefaultRetryConfig
//! |-- delay_strategy.rs # RetryDelayStrategy enum
//! |-- events.rs # Event type definitions
//! |-- error.rs # Error type definitions
//! |-- executor.rs # RetryExecutor executor
//! ```
//!
//! ## Core Features
//!
//! - ✅ **Type-Safe Retry** - Use generic API to support any return type
//! - ✅ **Multiple Delay Strategies** - Support fixed delay, random delay,
//! exponential backoff
//! - ✅ **Flexible Error Handling** - Result-based error handling with error
//! type identification
//! - ✅ **Result-Driven Retry** - Support retry logic based on return values
//! - ✅ **Event Listening** - Support various event callbacks during retry
//! process
//! - ✅ **Configuration Integration** - Seamless integration with
//! qubit-config's config module
//! - ✅ **Timeout Control** - Support single operation timeout and overall
//! timeout control
//! - ✅ **Sync and Async** - Support both synchronous and asynchronous
//! operation retries
//!
//! ## Usage Examples
//!
//! ### Basic Synchronous Retry
//! ```rust
//! use qubit_retry::{RetryBuilder, RetryDelayStrategy, RetryResult, RetryEvent};
//! use std::time::Duration;
//!
//! // Basic retry configuration
//! let executor = RetryBuilder::new()
//! .set_max_attempts(3)
//! .set_delay_strategy(RetryDelayStrategy::Fixed { delay: Duration::from_secs(1) })
//! .failed_on_results(vec!["RETRY".to_string(), "TEMP_FAIL".to_string()])
//! .on_retry(|event: &RetryEvent<String>| println!("Retry attempt {}", event.attempt_count()))
//! .build();
//!
//! // Use RetryResult type alias to simplify return type
//! let result: RetryResult<String> = executor.run(|| -> Result<String, Box<dyn std::error::Error + Send + Sync>> {
//! // Can use ? operator, io::Error will be automatically converted to
//! // RetryError through From trait
//! // Example: std::fs::read_to_string("config.txt")?;
//! Ok("SUCCESS".to_string())
//! });
//!
//! assert!(result.is_ok());
//! ```
//!
//! ### Async Retry with Timeout Control
//! ```rust,no_run
//! use qubit_retry::{RetryBuilder, RetryResult};
//! use std::time::Duration;
//!
//! # async fn example() {
//! // Configure timeout control
//! let executor = RetryBuilder::<String>::new()
//! .set_max_attempts(3)
//! .set_operation_timeout(Some(Duration::from_secs(5))) // Max 5 seconds per operation
//! .set_max_duration(Some(Duration::from_secs(30))) // Max 30 seconds total
//! .build();
//!
//! // Use RetryResult to simplify async function return type
//! let result: RetryResult<String> = executor.run_async(|| async {
//! // Async operation timeout will be truly interrupted
//! // Can use ? operator, errors will be automatically converted
//! // Example: tokio::fs::read_to_string("config.txt").await?;
//! Ok("SUCCESS".to_string())
//! }).await;
//!
//! assert!(result.is_ok());
//! # }
//! ```
//!
//! For detailed usage, please refer to the documentation of each struct.
//!
//! ## Author
//!
//! Haixing Hu
// Re-export public API
pub use RetryBuilder;
pub use RetryConfig;
pub use DefaultRetryConfig;
pub use RetryDelayStrategy;
pub use RetryError;
pub use ;
pub use RetryExecutor;
pub use SimpleRetryConfig;
// Common type aliases
pub type RetryResult<T> = ;
/// Type alias for retry builder using default configuration
///
/// This is the most commonly used `RetryBuilder` type, using
/// `DefaultRetryConfig` as the configuration type.
///
/// # Example
///
/// ```rust
/// use qubit_retry::DefaultRetryBuilder;
///
/// let builder = DefaultRetryBuilder::<String>::new()
/// .set_max_attempts(3)
/// .build();
/// ```
pub type DefaultRetryBuilder<T> = ;
/// Type alias for retry executor using default configuration
///
/// This is the most commonly used `RetryExecutor` type, using
/// `DefaultRetryConfig` as the configuration type.
///
/// # Example
///
/// ```rust
/// use qubit_retry::{RetryBuilder, DefaultRetryExecutor};
///
/// let executor: DefaultRetryExecutor<String> = RetryBuilder::new()
/// .set_max_attempts(3)
/// .build();
/// ```
pub type DefaultRetryExecutor<T> = ;