refactor: parse systemd state strings at the bus boundary

This commit is contained in:
Willem Vanhulle committed 2026-10-21 12:12:49 +02:00
1 parent 9812a85443
commit 741e6d13bb
2 files changed
+24 -30

No files matched your search

-28
View File
@@ -10,20 +10,6 @@ pub enum ActiveState {
Failed,
}
impl ActiveState {
#[must_use]
pub fn parse(raw: &str) -> Self {
match raw {
"activating" => Self::Activating,
"active" => Self::Active,
"deactivating" => Self::Deactivating,
"reloading" => Self::Reloading,
"failed" => Self::Failed,
_ => Self::Inactive,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum JobResult {
Done,
@@ -34,20 +20,6 @@ pub enum JobResult {
Dependency,
}
impl JobResult {
#[must_use]
pub fn parse(raw: &str) -> Self {
match raw {
"done" => Self::Done,
"skipped" => Self::Skipped,
"canceled" => Self::Canceled,
"timeout" => Self::Timeout,
"dependency" => Self::Dependency,
_ => Self::Failed,
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct UnitFacts {
pub name: String,
+24 -2
View File
@@ -298,7 +298,7 @@ fn parse_job_signal(message: &Message, member: &str) -> Option<Signal> {
message.read4().ok()?;
Some(Signal::JobRemoved {
id,
result: JobResult::parse(&result),
result: job_result_from_bus(&result),
})
}
_ => None,
@@ -329,9 +329,31 @@ fn activity_from(properties: &PropMap) -> Activity {
state: properties
.get("ActiveState")
.and_then(|value| value.0.as_str())
.map(ActiveState::parse),
.map(active_state_from_bus),
inactive_exit: monotonic("InactiveExitTimestampMonotonic"),
active_enter: monotonic("ActiveEnterTimestampMonotonic"),
active_exit: monotonic("ActiveExitTimestampMonotonic"),
}
}
fn active_state_from_bus(raw: &str) -> ActiveState {
match raw {
"activating" => ActiveState::Activating,
"active" => ActiveState::Active,
"deactivating" => ActiveState::Deactivating,
"reloading" => ActiveState::Reloading,
"failed" => ActiveState::Failed,
_ => ActiveState::Inactive,
}
}
fn job_result_from_bus(raw: &str) -> JobResult {
match raw {
"done" => JobResult::Done,
"skipped" => JobResult::Skipped,
"canceled" => JobResult::Canceled,
"timeout" => JobResult::Timeout,
"dependency" => JobResult::Dependency,
_ => JobResult::Failed,
}
}