summaryrefslogtreecommitdiffstats
path: root/src/db/model
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-22 10:36:24 +0000
committeraur-build <aur-build@localhost>2026-11-22 10:36:24 +0000
commit3dc71b2f5160ef9bd46143eed0edb5d2557b58e6 (patch)
tree7cc7169181b4bdd73fd8817f8c1d7cce6e6998a8 /src/db/model
parent9dc9087d89891c6e5ef7e5dc084dd13c8611843e (diff)
downloadaur-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')
-rw-r--r--src/db/model/build_state.rs57
-rw-r--r--src/db/model/mod.rs4
-rw-r--r--src/db/model/state.rs22
3 files changed, 22 insertions, 61 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!(
diff --git a/src/db/model/mod.rs b/src/db/model/mod.rs
index aef6a47..df861da 100644
--- a/src/db/model/mod.rs
+++ b/src/db/model/mod.rs
@@ -209,12 +209,12 @@ mod state;
pub(crate) use state::StateEnum;
-pub use build_state::{BUILD_STEPS, BuildState, StepState};
-pub use state::{CandidateState, SubscriptionState, candidate_kind, notice_kind};
+pub use build_state::{BuildState, StepState, BUILD_STEPS};
#[cfg(feature = "test-support")]
pub use state::ReleaseState;
#[cfg(not(feature = "test-support"))]
pub(crate) use state::ReleaseState;
+pub use state::{candidate_kind, notice_kind, CandidateState, SubscriptionState};
#[cfg(test)]
mod tests {
diff --git a/src/db/model/state.rs b/src/db/model/state.rs
index 18860ff..4057652 100644
--- a/src/db/model/state.rs
+++ b/src/db/model/state.rs
@@ -1,6 +1,5 @@
use serde::{Deserialize, Serialize};
-
use crate::db::model::build_state::{BuildState, StepState};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
@@ -40,9 +39,9 @@ impl CandidateState {
*self == CandidateState::PendingReview
}
- fn can_transition(&self, to: CandidateState) -> bool {
- use CandidateState::*;
- if *self == to {
+ fn can_transition(self, to: CandidateState) -> bool {
+ use CandidateState::{Approved, Blocked, PendingReview, Rejected, Superseded};
+ if self == to {
return true;
}
match self {
@@ -54,11 +53,7 @@ impl CandidateState {
}
pub(crate) fn predecessors(to: CandidateState) -> Vec<&'static str> {
- CandidateState::ALL
- .iter()
- .filter(|from| from.can_transition(to))
- .map(|from| from.as_str())
- .collect()
+ CandidateState::ALL.iter().filter(|from| from.can_transition(to)).map(CandidateState::as_str).collect()
}
}
@@ -78,7 +73,7 @@ pub mod candidate_kind {
/// only way to reach it, and the alias is what carries the
/// feature-conditional visibility.
mod release_state {
- use super::*;
+ use super::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
@@ -101,11 +96,8 @@ pub use release_state::ReleaseState;
pub(crate) use release_state::ReleaseState;
impl ReleaseState {
- const ALL: &'static [ReleaseState] = &[
- ReleaseState::Published,
- ReleaseState::Withdrawn,
- ReleaseState::FailedUnbuilt,
- ];
+ const ALL: &'static [ReleaseState] =
+ &[ReleaseState::Published, ReleaseState::Withdrawn, ReleaseState::FailedUnbuilt];
pub fn as_str(&self) -> &'static str {
match self {