use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Label {
Fresh,
Steady,
Elevated,
Tilt,
Fatigued,
Recovery,
}
impl Label {
#[must_use]
pub const fn short(self) -> &'static str {
match self {
Self::Fresh => "FRESH",
Self::Steady => "STEADY",
Self::Elevated => "ELEVATED",
Self::Tilt => "TILT",
Self::Fatigued => "FATIGUED",
Self::Recovery => "RECOVERY",
}
}
#[must_use]
pub const fn color_hint(self) -> ColorHint {
match self {
Self::Fresh | Self::Steady => ColorHint::Phosphor,
Self::Elevated | Self::Fatigued => ColorHint::Amber,
Self::Tilt => ColorHint::Red,
Self::Recovery => ColorHint::MutedOlive,
}
}
}
impl std::fmt::Display for Label {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.short())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ColorHint {
Phosphor,
Amber,
Red,
MutedOlive,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn short_labels_are_uppercase_single_word() {
for l in [
Label::Fresh,
Label::Steady,
Label::Elevated,
Label::Tilt,
Label::Fatigued,
Label::Recovery,
] {
assert!(l.short().chars().all(|c| c.is_ascii_uppercase()));
assert!(!l.short().contains(' '));
}
}
#[test]
fn color_hints_match_spec() {
assert_eq!(Label::Fresh.color_hint(), ColorHint::Phosphor);
assert_eq!(Label::Steady.color_hint(), ColorHint::Phosphor);
assert_eq!(Label::Elevated.color_hint(), ColorHint::Amber);
assert_eq!(Label::Fatigued.color_hint(), ColorHint::Amber);
assert_eq!(Label::Tilt.color_hint(), ColorHint::Red);
assert_eq!(Label::Recovery.color_hint(), ColorHint::MutedOlive);
}
}