Skip to main content

fleetreach_core/
severity.rs

1use serde::{Deserialize, Serialize};
2
3/// Advisory severity, derived from the advisory's CVSS score (`Unknown` when the
4/// advisory carries no score).
5///
6/// Variants are declared in **ascending** order so the derived `Ord` makes
7/// `Critical` the greatest. That gives us two things for free:
8/// `iter().max()` over a set of severities yields the worst one (drives
9/// `Summary::max_severity`), and a "severity descending" sort is a plain reverse.
10///
11/// Serializes as lowercase strings (`"critical"`, `"high"`, …) per the JSON
12/// schema — independent of declaration order.
13///
14/// ```
15/// use fleetreach_core::Severity;
16///
17/// assert!(Severity::Critical > Severity::High);
18/// assert!(Severity::Low > Severity::Unknown);
19///
20/// let worst = [Severity::Low, Severity::Critical, Severity::Medium]
21///     .into_iter()
22///     .max();
23/// assert_eq!(worst, Some(Severity::Critical));
24/// ```
25#[derive(
26    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize,
27)]
28#[serde(rename_all = "lowercase")]
29pub enum Severity {
30    #[default]
31    Unknown,
32    Low,
33    Medium,
34    High,
35    Critical,
36}