diff options
| author | John Turner <jturner.usa@gmail.com> | 2025-11-07 20:57:48 +0000 |
|---|---|---|
| committer | John Turner <jturner.usa@gmail.com> | 2025-11-08 22:13:14 +0000 |
| commit | b147d967d45092d6e289483e48ad4a91e3b89a14 (patch) | |
| tree | 96fc18c245cd3e78e6371c367a474c9126d22486 /src/atom/mod.rs | |
| parent | 5fd26e7c81899fabc066d8eefc7a8ec2b27e6351 (diff) | |
| download | gentoo-utils-b147d967d45092d6e289483e48ad4a91e3b89a14.tar.gz | |
put version and version operator in the same Option in the Atom struct
All atoms must either have a version with a version operator, or have
no version and no version operator. Putting these in the same Option
helps encode that into the type system.
Diffstat (limited to 'src/atom/mod.rs')
| -rw-r--r-- | src/atom/mod.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/atom/mod.rs b/src/atom/mod.rs index ffb9c61..eb7537b 100644 --- a/src/atom/mod.rs +++ b/src/atom/mod.rs @@ -106,15 +106,23 @@ pub struct UseDep { #[derive(Clone, Debug, Get)] pub struct Atom { blocker: Option<Blocker>, - version_operator: Option<VersionOperator>, category: Category, name: Name, - version: Option<Version>, + version: Option<(VersionOperator, Version)>, slot: Option<Slot>, #[get(kind = "deref")] usedeps: Vec<UseDep>, } +impl Atom { + pub fn version_operator(&self) -> Option<VersionOperator> { + match self.version { + Some((operator, _)) => Some(operator), + None => None, + } + } +} + impl fmt::Display for Blocker { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { @@ -299,7 +307,7 @@ impl fmt::Display for Atom { write!(f, "{blocker}")?; } - if let Some(version_operator) = self.version_operator.as_ref() { + if let Some(version_operator) = self.version_operator().as_ref() { write!(f, "{version_operator}")?; } @@ -307,7 +315,7 @@ impl fmt::Display for Atom { write!(f, "/")?; write!(f, "{}", self.name)?; - if let Some(version) = self.version.as_ref() { + if let Some((_, version)) = self.version.as_ref() { write!(f, "-{version}")?; } |
