Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion crates/uv-pypi-types/src/requirement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub enum RequirementError {
///
/// The main change is using [`RequirementSource`] to represent all supported package sources over
/// [`VersionOrUrl`], which collapses all URL sources into a single stringly type.
#[derive(Debug, Clone, Ord, PartialOrd, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Requirement {
pub name: PackageName,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
Expand Down Expand Up @@ -136,6 +136,35 @@ impl PartialEq for Requirement {

impl Eq for Requirement {}

impl Ord for Requirement {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
let Self {
name,
extras,
marker,
source,
origin: _,
} = self;
let Self {
name: other_name,
extras: other_extras,
marker: other_marker,
source: other_source,
origin: _,
} = other;
name.cmp(other_name)
.then_with(|| extras.cmp(other_extras))
.then_with(|| marker.cmp(other_marker))
.then_with(|| source.cmp(other_source))
}
}

impl PartialOrd for Requirement {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}

impl From<Requirement> for uv_pep508::Requirement<VerbatimUrl> {
/// Convert a [`Requirement`] to a [`uv_pep508::Requirement`].
fn from(requirement: Requirement) -> Self {
Expand Down
Loading