derive Hash for Atom and similar types

This commit is contained in:
John Turner
2025-11-23 03:30:37 +00:00
parent f8149b43d4
commit 5be1e5c37a
2 changed files with 29 additions and 25 deletions

View File

@@ -12,13 +12,13 @@ use itertools::Itertools;
mod parsers; mod parsers;
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Blocker { pub enum Blocker {
Weak, Weak,
Strong, Strong,
} }
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum VersionOperator { pub enum VersionOperator {
Lt, Lt,
Gt, Gt,
@@ -28,19 +28,20 @@ pub enum VersionOperator {
Roughly, Roughly,
} }
#[derive(Clone, Debug, PartialEq, Eq, Get)] #[derive(Clone, Debug, PartialEq, Eq, Hash, Get)]
pub struct Category(#[get(method = "get", kind = "deref")] String); pub struct Category(#[get(method = "get", kind = "deref")] String);
#[derive(Clone, Debug, PartialEq, Eq, Get)] #[derive(Clone, Debug, PartialEq, Eq, Hash, Get)]
pub struct Name(#[get(method = "get", kind = "deref")] String); pub struct Name(#[get(method = "get", kind = "deref")] String);
#[derive(Clone, Debug, Get)] #[derive(Clone, Debug, Hash, Get)]
pub struct VersionNumber(#[get(method = "get", kind = "deref")] String); pub struct VersionNumber(#[get(method = "get", kind = "deref")] String);
#[derive(Debug, Clone, Get)] #[allow(clippy::derived_hash_with_manual_eq)]
#[derive(Debug, Clone, Hash, Get)]
struct VersionNumbers(#[get(method = "get", kind = "deref")] Vec<VersionNumber>); struct VersionNumbers(#[get(method = "get", kind = "deref")] Vec<VersionNumber>);
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum VersionSuffixKind { pub enum VersionSuffixKind {
Alpha, Alpha,
Beta, Beta,
@@ -49,19 +50,22 @@ pub enum VersionSuffixKind {
P, P,
} }
#[derive(Clone, Debug, Get)] #[allow(clippy::derived_hash_with_manual_eq)]
#[derive(Clone, Debug, Hash, Get)]
pub struct VersionSuffix { pub struct VersionSuffix {
kind: VersionSuffixKind, kind: VersionSuffixKind,
number: Option<VersionNumber>, number: Option<VersionNumber>,
} }
#[derive(Debug, Clone, Get)] #[allow(clippy::derived_hash_with_manual_eq)]
#[derive(Debug, Clone, Hash, Get)]
pub struct VersionSuffixes(#[get(method = "get", kind = "deref")] Vec<VersionSuffix>); pub struct VersionSuffixes(#[get(method = "get", kind = "deref")] Vec<VersionSuffix>);
#[derive(Debug, Clone, Get, PartialEq, Eq)] #[derive(Debug, Clone, Get, PartialEq, Eq, Hash)]
pub struct BuildId(#[get(method = "get", kind = "deref")] String); pub struct BuildId(#[get(method = "get", kind = "deref")] String);
#[derive(Clone, Debug, Get)] #[allow(clippy::derived_hash_with_manual_eq)]
#[derive(Clone, Debug, Hash, Get)]
pub struct Version { pub struct Version {
numbers: VersionNumbers, numbers: VersionNumbers,
letter: Option<char>, letter: Option<char>,
@@ -70,19 +74,19 @@ pub struct Version {
build_id: Option<BuildId>, build_id: Option<BuildId>,
} }
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct Wildcard; pub struct Wildcard;
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum SlotOperator { pub enum SlotOperator {
Eq, Eq,
Star, Star,
} }
#[derive(Clone, Debug, PartialEq, Eq, Get)] #[derive(Clone, Debug, PartialEq, Eq, Hash, Get)]
pub struct SlotName(#[get(method = "name", kind = "deref")] String); pub struct SlotName(#[get(method = "name", kind = "deref")] String);
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum Slot { pub enum Slot {
Wildcard, Wildcard,
Equal, Equal,
@@ -96,28 +100,28 @@ pub enum Slot {
}, },
} }
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum UseDepNegate { pub enum UseDepNegate {
Minus, Minus,
Exclamation, Exclamation,
} }
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum UseDepSign { pub enum UseDepSign {
Enabled, Enabled,
Disabled, Disabled,
} }
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum UseDepCondition { pub enum UseDepCondition {
Eq, Eq,
Question, Question,
} }
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Repo(String); pub struct Repo(String);
#[derive(Clone, Debug, PartialEq, Eq, Get)] #[derive(Clone, Debug, PartialEq, Eq, Hash, Get)]
pub struct UseDep { pub struct UseDep {
negate: Option<UseDepNegate>, negate: Option<UseDepNegate>,
flag: UseFlag, flag: UseFlag,
@@ -125,13 +129,13 @@ pub struct UseDep {
condition: Option<UseDepCondition>, condition: Option<UseDepCondition>,
} }
#[derive(Clone, Debug, PartialEq, Eq, Get)] #[derive(Clone, Debug, PartialEq, Eq, Hash, Get)]
pub struct Cp { pub struct Cp {
category: Category, category: Category,
name: Name, name: Name,
} }
#[derive(Clone, Debug, PartialEq, Eq, Get)] #[derive(Clone, Debug, PartialEq, Eq, Hash, Get)]
pub struct Cpv { pub struct Cpv {
category: Category, category: Category,
name: Name, name: Name,
@@ -139,7 +143,7 @@ pub struct Cpv {
slot: Option<Slot>, slot: Option<Slot>,
} }
#[derive(Clone, Debug, Get, PartialEq, Eq)] #[derive(Clone, Debug, Get, PartialEq, Eq, Hash)]
pub struct Atom { pub struct Atom {
blocker: Option<Blocker>, blocker: Option<Blocker>,
category: Category, category: Category,

View File

@@ -4,10 +4,10 @@ use get::Get;
mod parsers; mod parsers;
#[derive(Clone, Debug, PartialEq, Eq, Get)] #[derive(Clone, Debug, PartialEq, Eq, Hash, Get)]
pub struct UseFlag(#[get(method = "name", kind = "deref")] String); pub struct UseFlag(#[get(method = "name", kind = "deref")] String);
#[derive(Clone, Debug, PartialEq, Eq, Get)] #[derive(Clone, Debug, PartialEq, Eq, Hash, Get)]
pub struct IUseFlag { pub struct IUseFlag {
default: bool, default: bool,
flag: UseFlag, flag: UseFlag,