diff options
| author | aur-build <aur-build@localhost> | 2026-11-22 10:36:24 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-22 10:36:24 +0000 |
| commit | 3dc71b2f5160ef9bd46143eed0edb5d2557b58e6 (patch) | |
| tree | 7cc7169181b4bdd73fd8817f8c1d7cce6e6998a8 /src/db/model/build_state.rs | |
| parent | 9dc9087d89891c6e5ef7e5dc084dd13c8611843e (diff) | |
| download | aur-build-3dc71b2f5160ef9bd46143eed0edb5d2557b58e6.tar.gz aur-build-3dc71b2f5160ef9bd46143eed0edb5d2557b58e6.zip | |
rustfmt,lints: pin the formatting, adopt the idiom lints, pay them off
rustfmt.toml fixes the shape the tree is written in (120 columns, small
items kept on one line) and one canonical pass makes it the truth.
[lints.clippy] names the idiom lints worth enforcing and leaves out the
two that would add doc-comment boilerplate rather than remove it. The
tree pays them off here: write!/writeln! instead of push_str(&format!()),
let-else instead of match-on-Option, borrows where a thread entry point
only reads what it owns, no `&self` on a Copy state and no `self` nobody
reads.
ops::to_prometheus gains one gauge helper: a metric's HELP, TYPE and
value are now emitted by the same call instead of three.
Diffstat (limited to 'src/db/model/build_state.rs')
| -rw-r--r-- | src/db/model/build_state.rs | 57 |
1 files changed, 13 insertions, 44 deletions
diff --git a/src/db/model/build_state.rs b/src/db/model/build_state.rs index 37eee79..478f93a 100644 --- a/src/db/model/build_state.rs +++ b/src/db/model/build_state.rs @@ -1,6 +1,5 @@ use serde::{Deserialize, Serialize}; - #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub enum BuildState { Queued, @@ -42,17 +41,14 @@ impl BuildState { } pub fn is_terminal(&self) -> bool { - matches!( - self, - BuildState::Succeeded | BuildState::Failed | BuildState::Cancelled - ) + matches!(self, BuildState::Succeeded | BuildState::Failed | BuildState::Cancelled) } /// The transition table itself. `predecessors` is how production /// enforces it; nothing outside this module asks the question directly. - fn can_transition(&self, to: BuildState) -> bool { - use BuildState::*; - if *self == to { + fn can_transition(self, to: BuildState) -> bool { + use BuildState::{BlockedMissingDep, Cancelled, Failed, Leased, Queued, Running, Succeeded}; + if self == to { return true; } match self { @@ -67,20 +63,11 @@ impl BuildState { } pub(crate) fn predecessors(to: BuildState) -> Vec<&'static str> { - BuildState::ALL - .iter() - .filter(|from| from.can_transition(to)) - .map(|from| from.as_str()) - .collect() + BuildState::ALL.iter().filter(|from| from.can_transition(to)).map(BuildState::as_str).collect() } pub fn active() -> &'static [BuildState] { - &[ - BuildState::Queued, - BuildState::Running, - BuildState::Leased, - BuildState::BlockedMissingDep, - ] + &[BuildState::Queued, BuildState::Running, BuildState::Leased, BuildState::BlockedMissingDep] } } @@ -130,9 +117,9 @@ impl StepState { matches!(self, StepState::Succeeded | StepState::Skipped) } - fn can_transition(&self, to: StepState) -> bool { - use StepState::*; - if *self == to { + fn can_transition(self, to: StepState) -> bool { + use StepState::{Failed, Interrupted, Pending, Running, Skipped, Succeeded}; + if self == to { return true; } match self { @@ -144,11 +131,7 @@ impl StepState { } pub(crate) fn predecessors(to: StepState) -> Vec<&'static str> { - StepState::ALL - .iter() - .filter(|from| from.can_transition(to)) - .map(|from| from.as_str()) - .collect() + StepState::ALL.iter().filter(|from| from.can_transition(to)).map(StepState::as_str).collect() } } @@ -158,18 +141,8 @@ impl std::fmt::Display for StepState { } } -pub const BUILD_STEPS: &[&str] = &[ - "materialize", - "plan", - "chroot", - "sources", - "pkgver", - "build", - "collect", - "verify", - "ingest", - "publish", -]; +pub const BUILD_STEPS: &[&str] = + &["materialize", "plan", "chroot", "sources", "pkgver", "build", "collect", "verify", "ingest", "publish"]; #[cfg(test)] mod tests { @@ -192,11 +165,7 @@ mod tests { #[test] fn the_transition_table_is_the_machine_the_code_actually_uses() { let reachable = |from: BuildState| -> Vec<&'static str> { - BuildState::ALL - .iter() - .filter(|to| from.can_transition(**to)) - .map(|to| to.as_str()) - .collect() + BuildState::ALL.iter().filter(|to| from.can_transition(**to)).map(super::BuildState::as_str).collect() }; assert_eq!(reachable(BuildState::Queued), ["queued", "leased", "running", "blocked_missing_dep", "cancelled"]); assert_eq!( |
