From 7faff05dae47e5957e995caed1428ccd0c408685 Mon Sep 17 00:00:00 2001 From: Le Song <781226451@qq.com> Date: Thu, 19 Feb 2026 15:22:36 +0800 Subject: [PATCH] fix(cron): align JobType conversions: add JobType <-> &str conversion via From/TryFrom --- src/cron/types.rs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/cron/types.rs b/src/cron/types.rs index f6d3c66c5..b8baf25d5 100644 --- a/src/cron/types.rs +++ b/src/cron/types.rs @@ -9,19 +9,26 @@ pub enum JobType { Agent, } -impl JobType { - pub(crate) fn as_str(&self) -> &'static str { - match self { - Self::Shell => "shell", - Self::Agent => "agent", +impl From for &'static str { + fn from(value: JobType) -> Self { + match value { + JobType::Shell => "shell", + JobType::Agent => "agent", } } +} - pub(crate) fn parse(raw: &str) -> Self { - if raw.eq_ignore_ascii_case("agent") { - Self::Agent - } else { - Self::Shell +impl TryFrom<&str> for JobType { + type Error = String; + + fn try_from(value: &str) -> Result { + match value.to_lowercase().as_str() { + "shell" => Ok(JobType::Shell), + "agent" => Ok(JobType::Agent), + _ => Err(format!( + "Invalid job type '{}'. Expected one of: 'shell', 'agent'", + value + )), } } }