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

@ -84,8 +84,11 @@ pub struct AgentWanted {
/// than part of a declaration it only half understands. Adding a state means
/// adding a variant here and shipping it to both ends — which is the intended
/// workflow, not an obstacle to route around with a catch-all variant.
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[derive(
Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize, strum::IntoStaticStr,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum AgentState {
/// Exists on the hive and is running.
Up,
@ -112,16 +115,13 @@ pub enum AgentState {
impl AgentState {
/// The wire spelling, for a reader that renders rather than decodes.
///
/// Kept beside the enum so it cannot drift from the `rename_all` above;
/// a test pins the two together.
/// Derived (`#[strum(serialize_all = "snake_case")]`) from the same
/// convention as the `serde(rename_all)` above, rather than a
/// hand-written match kept in sync with it by hand; a test still pins
/// the two together.
#[must_use]
pub fn as_str(self) -> &'static str {
match self {
AgentState::Up => "up",
AgentState::Offline => "offline",
AgentState::Paused => "paused",
AgentState::Destroyed => "destroyed",
}
self.into()
}
}