From b147d967d45092d6e289483e48ad4a91e3b89a14 Mon Sep 17 00:00:00 2001 From: John Turner Date: Fri, 7 Nov 2025 20:57:48 +0000 Subject: 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. --- src/atom/mod.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/atom/mod.rs') 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, - version_operator: Option, category: Category, name: Name, - version: Option, + version: Option<(VersionOperator, Version)>, slot: Option, #[get(kind = "deref")] usedeps: Vec, } +impl Atom { + pub fn version_operator(&self) -> Option { + 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}")?; } -- cgit v1.2.3