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 /// The attempt succeeded — reset the breaker's failure count.
17 Success,
18 /// The attempt failed transiently and may succeed if retried. `retry_after`
19 /// carries a server-supplied hint (e.g. a parsed `Retry-After` header).
20 Transient { retry_after: Option<Duration> },
21 /// The attempt failed permanently — retrying cannot help (auth,
22 /// validation).
23 Permanent,
24}
25
26impl Outcome {
27 /// Whether this outcome should be retried.
28 #[must_use]
29 pub const fn is_transient(self) -> bool {
30 matches!(self, Self::Transient { .. })
31 }
32}