Skip to main content

Crate retry_error

Crate retry_error 

Source
Expand description

Β§retry-error

An error attempt to represent multiple failures.

This crate implements RetryError, a type to use when you retry something a few times, and all those attempts can fail differently each time. Instead of returning only a single error, it records all of the errors received, in case they are different.

This crate is developed as part of Arti, a project to implement Tor in Rust. It’s used by higher-level crates that retry operations.

Β§Example

use retry_error::RetryError;

fn some_operation() -> anyhow::Result<bool> {
   unimplemented!(); // example
}

fn example() -> Result<(), RetryError<anyhow::Error>> {
   const N_ATTEMPTS: usize = 10;
   let mut err = RetryError::in_attempt_to("perform an example operation");
   for _ in 0..N_ATTEMPTS {
       match some_operation() {
           Ok(val) => return Ok(()),
           Err(e) => err.push(e),
       }
   }
   // All attempts failed; return all the errors.
   return Err(err);
}

License: MIT OR Apache-2.0

StructsΒ§

FormatDuration πŸ”’
A wrapper for formatting a Duration in a human-readable way. Produces output like β€œ2m 30s”, β€œ5h 12m”, β€œ45s”, β€œ500ms”.
FormatTimeAgo πŸ”’
A wrapper for formatting a Duration with β€œago” suffix.
RetryError
An error type for use when we’re going to do something a few times, and they might all fail.

EnumsΒ§

Attempt πŸ”’
Represents which attempts, in sequence, failed to complete.

FunctionsΒ§

current_instant πŸ”’
Return the current Instant.
current_system_time πŸ”’
Return the current system time.
fmt_duration_impl πŸ”’
Internal helper to format a duration.
fmt_error_with_sources
Helper: formats a std::error::Error and its sources (as "error: source")