recovery

Crates.iorecovery
lib.rsrecovery
version0.1.5
created_at2025-07-12 14:55:59.445517+00
updated_at2025-08-13 16:39:45.676472+00
descriptionTrait and derive macros to declare how errors should be retried
homepagehttps://github.com/popen2/recovery-rs
repository
max_upload_size
id1749382
size6,611
Zohar Zilberman (popen2)

documentation

README

🦀 Recovery

Trait and derive macros to declare how errors should be retried.

What it Does

This crate exports a trait that returns how an error should be retried:

pub trait Recovery {
    fn recovery(&self) -> RecoveryStrategy;
}

with:

  • RecoveryStrategy::Auto means the error is temporary, the operation should be tried again. Examples for this are connectivity issues, HTTP throttling or SERVICE_UNAVAILABLE, etc.
  • RecoveryStrategy::Manual means the operation might be recoverable, but shouldn't be done automatically. An example is HTTP UNAUTHORIZED errors which might indicate a configuration issue, but should only be retried once the underlying issue has been fixed.
  • RecoveryStrategy::Never is for errors that are definitely fatal, such as invalid inputs.

How to Use

You can implement Recovery for any error type. If your error is an enum (most likely) you can use #[derive(Recovery)]:

use recovery::Recovery;

#[derive(Recovery)]
pub enum MyError {
    #[recovery(auto)]
    Temporary,
    #[recovery(manual)]
    Maybe,
    #[recovery(never)]
    Fatal,
}

The macro also supports a default option if none is defined for one of the variants:

use recovery::Recovery;

#[derive(Recovery)]
#[recovery(never)]
pub enum Nah {
    Bad1,
    Bad2,
    Bad3,
    #[recovery(manual)]
    Maybe,
}

Finally, you can use #[recovery(transparent)] to use an internal variable's Recovery implementation:

use recovery::Recovery;

#[derive(Recovery)]
pub enum Outer {
    #[recovery(transparent)]
    Inner(Inner),
}

#[derive(Recovery)]
pub enum Inner {
    #[recovery(manual)]
    Maybe,
}
Commit count: 0

cargo fmt