Use from_range_bounds (#6879)

Not the most ergonomic api pubgrub has to offer, but better than rolling
our own.
This commit is contained in:
konsti 2024-08-30 22:06:55 +02:00 committed by GitHub
parent 34435d7d9d
commit 00c98a82b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -414,29 +414,10 @@ impl Default for RequiresPythonRange {
impl From<RequiresPythonRange> for Range<Version> {
fn from(value: RequiresPythonRange) -> Self {
match (value.0.as_ref(), value.1.as_ref()) {
(Bound::Included(lower), Bound::Included(upper)) => {
Range::from_range_bounds(lower.clone()..=upper.clone())
}
(Bound::Included(lower), Bound::Excluded(upper)) => {
Range::from_range_bounds(lower.clone()..upper.clone())
}
(Bound::Excluded(lower), Bound::Included(upper)) => {
Range::strictly_higher_than(lower.clone())
.intersection(&Range::lower_than(upper.clone()))
}
(Bound::Excluded(lower), Bound::Excluded(upper)) => {
Range::strictly_higher_than(lower.clone())
.intersection(&Range::strictly_lower_than(upper.clone()))
}
(Bound::Unbounded, Bound::Unbounded) => Range::full(),
(Bound::Unbounded, Bound::Included(upper)) => Range::lower_than(upper.clone()),
(Bound::Unbounded, Bound::Excluded(upper)) => Range::strictly_lower_than(upper.clone()),
(Bound::Included(lower), Bound::Unbounded) => Range::higher_than(lower.clone()),
(Bound::Excluded(lower), Bound::Unbounded) => {
Range::strictly_higher_than(lower.clone())
}
}
Range::from_range_bounds::<(Bound<Version>, Bound<Version>), _>((
value.0.into(),
value.1.into(),
))
}
}
@ -470,6 +451,12 @@ impl Deref for RequiresPythonBound {
}
}
impl From<RequiresPythonBound> for Bound<Version> {
fn from(bound: RequiresPythonBound) -> Self {
bound.0
}
}
impl PartialOrd for RequiresPythonBound {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))