/ crates / retry-error / README.md
README.md
 1  # retry-error
 2  
 3  An error attempt to represent multiple failures.
 4  
 5  This crate implements [`RetryError`], a type to use when you
 6  retry something a few times, and all those attempts can fail differently
 7  each time.  Instead of returning only a single error, it records
 8  _all of the errors received_, in case they are different.
 9  
10  This crate is developed as part of
11  [Arti](https://gitlab.torproject.org/tpo/core/arti/), a project to
12  implement [Tor](https://www.torproject.org/) in Rust.
13  It's used by higher-level crates that retry
14  operations.
15  
16  ### Example
17  
18  ```rust
19  use retry_error::RetryError;
20  
21  fn some_operation() -> anyhow::Result<bool> {
22     unimplemented!(); // example
23  }
24  
25  fn example() -> Result<(), RetryError<anyhow::Error>> {
26     const N_ATTEMPTS: usize = 10;
27     let mut err = RetryError::in_attempt_to("perform an example operation");
28     for _ in 0..N_ATTEMPTS {
29         match some_operation() {
30             Ok(val) => return Ok(()),
31             Err(e) => err.push(e),
32         }
33     }
34     // All attempts failed; return all the errors.
35     return Err(err);
36  }
37  ```
38  
39  License: MIT OR Apache-2.0