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//!
4//! Copyright (c) systemprompt.io — Business Source License 1.1.
5//! See <https://systemprompt.io> for licensing details.
6
7use std::time::Duration;
8
9/// How the resilience layer should treat the result of a single attempt.
10///
11/// Callers implement the mapping from their own error type to this enum and
12/// pass it as a `Fn(&E) -> Outcome` closure. [`Outcome::Transient`] failures
13/// are retried and count toward the circuit breaker; [`Outcome::Permanent`]
14/// failures fail fast but still count toward the breaker (a
15/// steadily-misconfigured dependency is unhealthy regardless of whether
16/// retrying would help).
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum Outcome {
19    Success,
20    Transient { retry_after: Option<Duration> },
21    Permanent,
22}
23
24impl Outcome {
25    #[must_use]
26    pub const fn is_transient(self) -> bool {
27        matches!(self, Self::Transient { .. })
28    }
29}