Watch
0
0
Fork
You've already forked hyperhive
0

convert hand-written enum as_str matches to strum derives workspace-wide

This commit is contained in:
damocles 2026-09-11 21:06:54 +02:00
commit 299add158f
14 changed files with 70 additions and 113 deletions

View file

@ -90,8 +90,9 @@ const MIGRATIONS: &[Migration] = &[Migration {
/// Status of a finished build attempt. Stored as the literal string in
/// the `status` column; `NULL` while the attempt is still in progress.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, strum::IntoStaticStr)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum BuildStatus {
/// Child exited with success.
Ok,
@ -101,10 +102,7 @@ pub enum BuildStatus {
impl BuildStatus {
fn as_str(self) -> &'static str {
match self {
Self::Ok => "ok",
Self::Fail => "fail",
}
self.into()
}
}

View file

@ -30,7 +30,8 @@ CREATE TABLE IF NOT EXISTS agent_power (
";
/// Per-agent power intent.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, strum::IntoStaticStr, strum::EnumString)]
#[strum(serialize_all = "snake_case")]
pub enum Wanted {
Up,
Offline,
@ -38,18 +39,14 @@ pub enum Wanted {
impl Wanted {
pub fn as_str(self) -> &'static str {
match self {
Wanted::Up => "up",
Wanted::Offline => "offline",
}
self.into()
}
/// Derived (`strum::EnumString`, the same `snake_case` convention
/// `as_str` uses) rather than a hand-written match kept in sync with
/// it by hand.
fn parse(s: &str) -> Option<Self> {
match s {
"up" => Some(Wanted::Up),
"offline" => Some(Wanted::Offline),
_ => None,
}
s.parse().ok()
}
/// Seed value from an observed running state (first boot after