diff options
| author | John Turner <jturner.usa@gmail.com> | 2025-11-21 04:33:55 +0000 |
|---|---|---|
| committer | John Turner <jturner.usa@gmail.com> | 2025-11-21 04:33:55 +0000 |
| commit | fb69d82e6f1dce4677114e717a5954bb9ab5c0e4 (patch) | |
| tree | 821f9aab0609c7242e333e1ac0819aca1b3ceef4 /src/atom/mod.rs | |
| parent | bf56ed1c61905b3abdba70aea84622619cffd8da (diff) | |
| download | gentoo-utils-fb69d82e6f1dce4677114e717a5954bb9ab5c0e4.tar.gz | |
build-id must not start with zero
Diffstat (limited to 'src/atom/mod.rs')
| -rw-r--r-- | src/atom/mod.rs | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/atom/mod.rs b/src/atom/mod.rs index 8cffa06..82cef15 100644 --- a/src/atom/mod.rs +++ b/src/atom/mod.rs @@ -58,13 +58,16 @@ pub struct VersionSuffix { #[derive(Debug, Clone, Get)] pub struct VersionSuffixes(#[get(method = "get", kind = "deref")] Vec<VersionSuffix>); +#[derive(Debug, Clone, Get, PartialEq, Eq)] +pub struct BuildId(#[get(method = "get", kind = "deref")] String); + #[derive(Clone, Debug, Get)] pub struct Version { numbers: VersionNumbers, letter: Option<char>, suffixes: VersionSuffixes, rev: Option<VersionNumber>, - build_id: Option<VersionNumber>, + build_id: Option<BuildId>, } #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -207,6 +210,22 @@ impl VersionNumber { } } +impl PartialOrd for BuildId { + fn partial_cmp(&self, other: &Self) -> Option<Ordering> { + Some(self.cmp(other)) + } +} + +impl Ord for BuildId { + fn cmp(&self, other: &Self) -> Ordering { + // build-id may not start with a zero so we dont need to strip them + self.get() + .len() + .cmp(&other.get().len()) + .then_with(|| self.get().cmp(other.get())) + } +} + impl PartialEq for VersionSuffix { fn eq(&self, other: &Self) -> bool { self.kind == other.kind @@ -373,7 +392,7 @@ impl PartialEq for Version { (None, None) => true, } && match (&self.build_id, &other.build_id) { - (Some(a), Some(b)) => matches!(a.cmp_as_ints(b), Ordering::Equal), + (Some(a), Some(b)) => a == b, (Some(_), None) | (None, Some(_)) => false, (None, None) => true, } @@ -426,7 +445,7 @@ impl Ord for Version { } match (&self.build_id, &other.build_id) { - (Some(a), Some(b)) => a.cmp_as_ints(b), + (Some(a), Some(b)) => a.cmp(b), (Some(_), None) => Ordering::Greater, (None, Some(_)) => Ordering::Less, (None, None) => Ordering::Equal, @@ -484,6 +503,12 @@ impl fmt::Display for VersionNumber { } } +impl fmt::Display for BuildId { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.get()) + } +} + impl fmt::Display for VersionSuffixKind { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { |
