recoverable

Crates.iorecoverable
lib.rsrecoverable
version0.1.0
created_at2025-10-03 13:29:02.205552+00
updated_at2026-01-08 09:31:57.776622+00
descriptionRecovery information and classification for resilience patterns.
homepagehttps://github.com/microsoft/oxidizer
repositoryhttps://github.com/microsoft/oxidizer
max_upload_size
id1866657
size36,807
(oxidizer-crates-io-bot)

documentation

README

Recoverable Logo

Recoverable

crate.io docs.rs MSRV CI Coverage License This crate was developed as part of the Oxidizer project

Recovery information and classification for resilience patterns.

Why

This crate provides types for classifying conditions based on their recoverability state, enabling consistent recovery behavior across different error types and resilience middleware.

Recovery Information

The recovery information describes whether recovering from an operation might help, not whether the operation succeeded or failed. Both successful operations and permanent failures should use RecoveryInfo::never since recovery is not necessary or desirable.

Core Types

  • RecoveryInfo: Classifies conditions as recoverable (transient) or non-recoverable (permanent/successful).
  • Recovery: A trait for types that can determine their recoverability.
  • RecoveryKind: An enum representing the kind of recovery that can be attempted.

Examples

Recovery Error

use recoverable::{Recovery, RecoveryInfo, RecoveryKind};

#[derive(Debug)]
enum DatabaseError {
    ConnectionTimeout,
    InvalidCredentials,
    TableNotFound,
}

impl Recovery for DatabaseError {
    fn recovery(&self) -> RecoveryInfo {
        match self {
            // Transient failure - might succeed if retried
            DatabaseError::ConnectionTimeout => RecoveryInfo::retry(),
            // Permanent failures - retrying won't help
            DatabaseError::InvalidCredentials => RecoveryInfo::never(),
            DatabaseError::TableNotFound => RecoveryInfo::never(),
        }
    }
}

let error = DatabaseError::ConnectionTimeout;
assert_eq!(error.recovery().kind(), RecoveryKind::Retry);

// For successful operations, also use never() since retry is unnecessary
let success_result: Result<(), DatabaseError> = Ok(());
// If we had a wrapper type for success, it would also return RecoveryInfo::never()

Retry Delay

You can specify when to retry an operation using the delay method:

use std::time::Duration;
use recoverable::{RecoveryInfo, RecoveryKind};

// Retry with a 30-second delay (e.g., from a Retry-After header)
let recovery = RecoveryInfo::retry().delay(Duration::from_secs(30));
assert_eq!(recovery.kind(), RecoveryKind::Retry);
assert_eq!(recovery.get_delay(), Some(Duration::from_secs(30)));

// Immediate retry
let immediate = RecoveryInfo::retry().delay(Duration::ZERO);
assert_eq!(immediate.get_delay(), Some(Duration::ZERO));

This crate was developed as part of The Oxidizer Project. Browse this crate's source code.
Commit count: 14

cargo fmt