From 00c98a82b0091b9ddaa052d20521687fe8da92d9 Mon Sep 17 00:00:00 2001 From: konsti Date: Fri, 30 Aug 2024 22:06:55 +0200 Subject: [PATCH] Use `from_range_bounds` (#6879) Not the most ergonomic api pubgrub has to offer, but better than rolling our own. --- crates/uv-resolver/src/requires_python.rs | 33 +++++++---------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/crates/uv-resolver/src/requires_python.rs b/crates/uv-resolver/src/requires_python.rs index 2656b331e..68e3cdd14 100644 --- a/crates/uv-resolver/src/requires_python.rs +++ b/crates/uv-resolver/src/requires_python.rs @@ -414,29 +414,10 @@ impl Default for RequiresPythonRange { impl From for Range { 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, Bound), _>(( + value.0.into(), + value.1.into(), + )) } } @@ -470,6 +451,12 @@ impl Deref for RequiresPythonBound { } } +impl From for Bound { + fn from(bound: RequiresPythonBound) -> Self { + bound.0 + } +} + impl PartialOrd for RequiresPythonBound { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other))