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); #[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, } -#[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); #[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, @@ -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 { 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 { 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 { 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 { Some(self.cmp(other)) @@ -774,38 +686,6 @@ mod test { assert_eq!(atom.to_string().as_str(), s); } - #[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 = [