summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-11-23 05:18:30 +0000
committerJohn Turner <jturner.usa@gmail.com>2025-11-23 05:18:30 +0000
commit86e2b4559a1043fcd1fb4ba41646434e45b432f3 (patch)
tree6d26c8c3cea74537eca5e22058ced4f3bac7a09f
parent5be1e5c37acb3d9d545a0e5b2992f0bf3148cc4e (diff)
downloadgentoo-utils-86e2b4559a1043fcd1fb4ba41646434e45b432f3.tar.gz
derive PartialEq and Eq for Atom and Atom related types
-rw-r--r--src/atom/mod.rs130
1 files changed, 5 insertions, 125 deletions
diff --git a/src/atom/mod.rs b/src/atom/mod.rs
index a483aaf..502554d 100644
--- a/src/atom/mod.rs
+++ b/src/atom/mod.rs
@@ -34,11 +34,10 @@ pub struct Category(#[get(method = "get", kind = "deref")] String);
#[derive(Clone, Debug, PartialEq, Eq, Hash, Get)]
pub struct Name(#[get(method = "get", kind = "deref")] String);
-#[derive(Clone, Debug, Hash, Get)]
+#[derive(Clone, Debug, PartialEq, Eq, Hash, Get)]
pub struct VersionNumber(#[get(method = "get", kind = "deref")] String);
-#[allow(clippy::derived_hash_with_manual_eq)]
-#[derive(Debug, Clone, Hash, Get)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash, Get)]
struct VersionNumbers(#[get(method = "get", kind = "deref")] Vec<VersionNumber>);
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -50,22 +49,19 @@ pub enum VersionSuffixKind {
P,
}
-#[allow(clippy::derived_hash_with_manual_eq)]
-#[derive(Clone, Debug, Hash, Get)]
+#[derive(Clone, Debug, Hash, PartialEq, Eq, Get)]
pub struct VersionSuffix {
kind: VersionSuffixKind,
number: Option<VersionNumber>,
}
-#[allow(clippy::derived_hash_with_manual_eq)]
-#[derive(Debug, Clone, Hash, Get)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash, Get)]
pub struct VersionSuffixes(#[get(method = "get", kind = "deref")] Vec<VersionSuffix>);
#[derive(Debug, Clone, Get, PartialEq, Eq, Hash)]
pub struct BuildId(#[get(method = "get", kind = "deref")] String);
-#[allow(clippy::derived_hash_with_manual_eq)]
-#[derive(Clone, Debug, Hash, Get)]
+#[derive(Clone, Debug, PartialEq, Eq, Hash, Get)]
pub struct Version {
numbers: VersionNumbers,
letter: Option<char>,
@@ -231,21 +227,6 @@ impl Ord for BuildId {
}
}
-impl PartialEq for VersionSuffix {
- fn eq(&self, other: &Self) -> bool {
- self.kind == other.kind
- && match (&self.number, &other.number) {
- (Some(a), Some(b)) => a.0 == b.0,
- (Some(a), None) if a.get().chars().all(|c| c == '0') => true,
- (None, Some(b)) if b.get().chars().all(|c| c == '0') => true,
- (Some(_), None) | (None, Some(_)) => false,
- (None, None) => true,
- }
- }
-}
-
-impl Eq for VersionSuffix {}
-
impl PartialOrd for VersionSuffix {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
@@ -269,23 +250,6 @@ impl Ord for VersionSuffix {
}
}
-impl PartialEq for VersionSuffixes {
- fn eq(&self, other: &Self) -> bool {
- let mut a = self.get().iter();
- let mut b = other.get().iter();
-
- loop {
- match (a.next(), b.next()) {
- (Some(a), Some(b)) if a == b => (),
- (Some(_) | None, Some(_)) | (Some(_), None) => break false,
- (None, None) => break true,
- }
- }
- }
-}
-
-impl Eq for VersionSuffixes {}
-
impl PartialOrd for VersionSuffixes {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
@@ -316,36 +280,6 @@ impl Ord for VersionSuffixes {
}
}
-impl PartialEq for VersionNumbers {
- fn eq(&self, other: &Self) -> bool {
- self.get()
- .first()
- .unwrap()
- .cmp_as_ints(other.get().first().unwrap())
- == Ordering::Equal
- && {
- let mut a = self.get().iter().skip(1);
- let mut b = other.get().iter().skip(1);
-
- loop {
- match (a.next(), b.next()) {
- (Some(a), Some(b)) => {
- let Ordering::Equal = a.cmp_as_str(b) else {
- return false;
- };
- }
- (Some(a), None) if a.get().chars().all(|c| c == '0') => (),
- (None, Some(b)) if b.get().chars().all(|c| c == '0') => (),
- (None, None) => break true,
- _ => break false,
- }
- }
- }
- }
-}
-
-impl Eq for VersionNumbers {}
-
impl PartialOrd for VersionNumbers {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
@@ -384,28 +318,6 @@ impl Ord for VersionNumbers {
}
}
-impl PartialEq for Version {
- fn eq(&self, other: &Self) -> bool {
- self.numbers == other.numbers
- && self.suffixes == other.suffixes
- && self.letter == other.letter
- && match (&self.rev, &other.rev) {
- (Some(a), Some(b)) => matches!(a.cmp_as_ints(b), Ordering::Equal),
- (Some(a), None) if a.get().chars().all(|c| c == '0') => true,
- (None, Some(b)) if b.get().chars().all(|c| c == '0') => true,
- (Some(_), None) | (None, Some(_)) => false,
- (None, None) => true,
- }
- && match (&self.build_id, &other.build_id) {
- (Some(a), Some(b)) => a == b,
- (Some(_), None) | (None, Some(_)) => false,
- (None, None) => true,
- }
- }
-}
-
-impl Eq for Version {}
-
impl PartialOrd for Version {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
@@ -775,38 +687,6 @@ mod test {
}
#[test]
- fn test_version_suffix_eq() {
- let a = VersionSuffix::parser()
- .parse_finished(InputIter::new("alpha0"))
- .unwrap();
- let b = VersionSuffix::parser()
- .parse_finished(InputIter::new("alpha"))
- .unwrap();
-
- assert_eq_display!(a, b);
- }
-
- #[test]
- fn test_version_eq() {
- let versions = [
- ("1", "1"),
- ("1", "1.0.0"),
- ("1.0", "1.0.0"),
- ("1.0.0_alpha0", "1.0.0_alpha"),
- ("1.0.0", "1.0.0-r0"),
- ];
-
- for (a, b) in versions.map(|(a, b)| {
- (
- Version::parser().parse_finished(InputIter::new(a)).unwrap(),
- Version::parser().parse_finished(InputIter::new(b)).unwrap(),
- )
- }) {
- assert_eq_display!(a, b);
- }
- }
-
- #[test]
fn test_version_cmp() {
let versions = [
("1.0.1", "1.0", Ordering::Greater),