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.
This commit is contained in:
John Turner
2025-11-07 20:57:48 +00:00
parent 5fd26e7c81
commit b147d967d4
2 changed files with 46 additions and 21 deletions

View File

@@ -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}")?;
}