Skip to main content

systemprompt_database/resilience/
classify.rs

1//! Error classification — the contract between a caller's error type and the
2//! resilience primitives.
3
4use std::time::Duration;
5
6/// How the resilience layer should treat the result of a single attempt.
7///
8/// Callers implement the mapping from their own error type to this enum and
9/// pass it as a `Fn(&E) -> Outcome` closure. [`Outcome::Transient`] failures
10/// are retried and count toward the circuit breaker; [`Outcome::Permanent`]
11/// failures fail fast but still count toward the breaker (a
12/// steadily-misconfigured dependency is unhealthy regardless of whether
13/// retrying would help).
14#[derive(Debug, Clone, Copy, PartialEq, Eq)]
15pub enum Outcome {
16    Success,
17    Transient { retry_after: Option<Duration> },
18    Permanent,
19}
20
21impl Outcome {
22    #[must_use]
23    pub const fn is_transient(self) -> bool {
24        matches!(self, Self::Transient { .. })
25    }
26}