Skip to content

Commit

Permalink
Require major.minor for RequestedVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
cnpryer committed Oct 29, 2023
1 parent 4778bfe commit 5d412b3
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions crates/huak-python-manager/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@ impl Default for Options<'static> {

#[derive(Debug, Clone)]
pub struct RequestedVersion {
pub major: Option<u8>,
pub minor: Option<u8>,
pub major: u8,
pub minor: u8,
pub patch: Option<u8>,
}

impl RequestedVersion {
/// Evaluates if some Python release's version is what was requested.
pub(crate) fn matches_version(&self, version: Version) -> bool {
self.major.map_or(true, |it| it == version.major)
&& self.minor.map_or(true, |it| it == version.minor)
self.major == version.major
&& self.minor == version.minor
&& self.patch.map_or(true, |it| it == version.patch)
}
}
Expand All @@ -128,24 +128,21 @@ impl FromStr for RequestedVersion {
};

Ok(RequestedVersion {
major: Some(major),
minor: Some(minor),
major,
minor,
patch,
})
}
}

impl Display for RequestedVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Some(major) = self.major {
write!(f, "{major}")?;
}
if let Some(minor) = self.minor {
write!(f, ".{minor}")?;
}
write!(f, "{}.{}", self.major, self.minor)?;

if let Some(patch) = self.patch {
write!(f, ".{patch}")?;
}

Ok(())
}
}
Expand Down

0 comments on commit 5d412b3

Please sign in to comment.