nexus_stats_core/enums.rs
1/// Directional change or anomaly direction.
2///
3/// Used by algorithms that detect shifts, anomalies, or trends in a signal.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum Direction {
6 /// No directional change detected.
7 Neutral,
8 /// Upward: mean shifted up, value is high, trend is rising.
9 Rising,
10 /// Downward: mean shifted down, value is low, trend is falling.
11 Falling,
12}
13
14/// System condition state.
15///
16/// Used by algorithms that monitor health, saturation, or pressure.
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum Condition {
19 /// Within acceptable bounds.
20 Normal,
21 /// Exceeded threshold — degraded performance.
22 Degraded,
23}
24
25/// Configuration error from building a stats primitive.
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub enum ConfigError {
28 /// A required parameter was not set.
29 Missing(&'static str),
30 /// A parameter value is invalid.
31 Invalid(&'static str),
32}
33
34impl core::fmt::Display for ConfigError {
35 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
36 match self {
37 Self::Missing(param) => write!(f, "configuration error: {param} must be set"),
38 Self::Invalid(msg) => write!(f, "configuration error: {msg}"),
39 }
40 }
41}
42
43#[cfg(feature = "std")]
44impl std::error::Error for ConfigError {}
45
46/// Error returned when a streaming update receives invalid data.
47///
48/// The library distinguishes two failure categories:
49/// - **Data errors** (NaN, Inf) → returned as `Result<_, DataError>`
50/// - **Programmer errors** (wrong dimensions, out-of-range) → panic
51///
52/// The library makes no assumptions about the caller's policy.
53/// Each system has different implications for bad data.
54#[derive(Debug, Clone, Copy, PartialEq, Eq)]
55pub enum DataError {
56 /// Input contained NaN.
57 NotANumber,
58 /// Input contained positive or negative infinity.
59 Infinite,
60 /// Input contained a negative value where non-negative was required.
61 Negative,
62}
63
64impl core::fmt::Display for DataError {
65 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
66 match self {
67 Self::NotANumber => write!(f, "input contained NaN"),
68 Self::Infinite => write!(f, "input contained infinity"),
69 Self::Negative => write!(f, "input contained a negative value"),
70 }
71 }
72}
73
74#[cfg(feature = "std")]
75impl std::error::Error for DataError {}