Skip to content

Commit e187a25

Browse files
committed
Rename some variants
1 parent e3eefcc commit e187a25

File tree

5 files changed

+60
-56
lines changed

5 files changed

+60
-56
lines changed

crates/uv-pep440/src/version.rs

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ impl Version {
534534
if value.is_empty() {
535535
self.without_local()
536536
} else {
537-
self.make_full().local = LocalVersion::Actual(value);
537+
self.make_full().local = LocalVersion::Segments(value);
538538
self
539539
}
540540
}
@@ -544,7 +544,7 @@ impl Version {
544544
#[must_use]
545545
pub fn with_local(mut self, value: LocalVersion) -> Self {
546546
match value {
547-
LocalVersion::Actual(segments) => self.with_local_segments(segments),
547+
LocalVersion::Segments(segments) => self.with_local_segments(segments),
548548
LocalVersion::Max => {
549549
self.make_full().local = value;
550550
self
@@ -628,7 +628,7 @@ impl Version {
628628
pre: small.pre(),
629629
post: small.post(),
630630
dev: small.dev(),
631-
local: LocalVersion::Actual(vec![]),
631+
local: LocalVersion::Segments(vec![]),
632632
};
633633
*self = Self {
634634
inner: Arc::new(VersionInner::Full { full }),
@@ -726,10 +726,10 @@ impl std::fmt::Display for Version {
726726
String::new()
727727
} else {
728728
match self.local() {
729-
LocalVersionSlice::Actual(_) => {
730-
format!("+{}", self.local().local_identifier_string())
729+
LocalVersionSlice::Segments(_) => {
730+
format!("+{}", self.local())
731731
}
732-
LocalVersionSlice::Sentinel => String::new(),
732+
LocalVersionSlice::Max => String::new(),
733733
}
734734
};
735735
write!(f, "{epoch}{release}{pre}{post}{dev}{local}")
@@ -849,7 +849,7 @@ impl FromStr for Version {
849849
/// `min, .devN, aN, bN, rcN, <no suffix>, .postN, max`.
850850
/// Its representation is thus:
851851
/// * The most significant 3 bits of Byte 2 corresponds to a value in
852-
/// the range 0-6 inclusive, corresponding to min, dev, pre-a, pre-b, pre-rc,
852+
/// the range 0-7 inclusive, corresponding to min, dev, pre-a, pre-b, pre-rc,
853853
/// no-suffix or post releases, respectively. `min` is a special version that
854854
/// does not exist in PEP 440, but is used here to represent the smallest
855855
/// possible version, preceding any `dev`, `pre`, `post` or releases. `max` is
@@ -1178,7 +1178,7 @@ impl VersionSmall {
11781178
fn local(&self) -> LocalVersionSlice {
11791179
// A "small" version is never used if the version has a non-zero number
11801180
// of local segments.
1181-
LocalVersionSlice::Actual(&[])
1181+
LocalVersionSlice::Segments(&[])
11821182
}
11831183

11841184
#[inline]
@@ -1200,13 +1200,13 @@ impl VersionSmall {
12001200

12011201
#[inline]
12021202
fn suffix_version(&self) -> u64 {
1203-
self.repr & 0x001F_FFFF
1203+
self.repr & Self::SUFFIX_MAX_VERSION
12041204
}
12051205

12061206
#[inline]
12071207
fn set_suffix_version(&mut self, value: u64) {
1208-
debug_assert!(value <= 0x001F_FFFF);
1209-
self.repr &= !0x001F_FFFF;
1208+
debug_assert!(value <= Self::SUFFIX_MAX_VERSION);
1209+
self.repr &= !Self::SUFFIX_MAX_VERSION;
12101210
self.repr |= value;
12111211
}
12121212
}
@@ -1404,51 +1404,55 @@ impl std::fmt::Display for Prerelease {
14041404
#[cfg_attr(feature = "rkyv", rkyv(derive(Debug, Eq, PartialEq, PartialOrd, Ord)))]
14051405
pub enum LocalVersion {
14061406
/// A sequence of local segments.
1407-
Actual(Vec<LocalSegment>),
1407+
Segments(Vec<LocalSegment>),
14081408
/// An internal-only value that compares greater to all other local versions.
14091409
Max,
14101410
}
14111411

14121412
/// Like [`LocalVersion`], but using a slice
14131413
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
14141414
pub enum LocalVersionSlice<'a> {
1415-
/// Like [`LocalVersion::Actual`]
1416-
Actual(&'a [LocalSegment]),
1415+
/// Like [`LocalVersion::Segments`]
1416+
Segments(&'a [LocalSegment]),
14171417
/// Like [`LocalVersion::Sentinel`]
1418-
Sentinel,
1418+
Max,
14191419
}
14201420

14211421
impl LocalVersion {
14221422
/// Convert the local version segments into a slice.
14231423
pub fn as_slice(&self) -> LocalVersionSlice<'_> {
14241424
match self {
1425-
LocalVersion::Actual(segments) => LocalVersionSlice::Actual(segments),
1426-
LocalVersion::Max => LocalVersionSlice::Sentinel,
1425+
LocalVersion::Segments(segments) => LocalVersionSlice::Segments(segments),
1426+
LocalVersion::Max => LocalVersionSlice::Max,
14271427
}
14281428
}
14291429

14301430
/// Clear the local version segments, if they exist.
14311431
pub fn clear(&mut self) {
14321432
match self {
1433-
Self::Actual(segments) => segments.clear(),
1434-
Self::Max => *self = Self::Actual(Vec::new()),
1433+
Self::Segments(segments) => segments.clear(),
1434+
Self::Max => *self = Self::Segments(Vec::new()),
14351435
}
14361436
}
14371437
}
14381438

1439-
impl LocalVersionSlice<'_> {
1440-
/// Output the local version identifier string.
1441-
///
1442-
/// [`LocalVersionSlice::Sentinel`] maps to `"[max]"` which is otherwise an illegal local
1443-
/// version because `[` and `]` are not allowed.
1444-
pub fn local_identifier_string(&self) -> String {
1439+
/// Output the local version identifier string.
1440+
///
1441+
/// [`LocalVersionSlice::Max`] maps to `"[max]"` which is otherwise an illegal local
1442+
/// version because `[` and `]` are not allowed.
1443+
impl std::fmt::Display for LocalVersionSlice<'_> {
1444+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14451445
match self {
1446-
LocalVersionSlice::Actual(segments) => segments
1447-
.iter()
1448-
.map(ToString::to_string)
1449-
.collect::<Vec<String>>()
1450-
.join("."),
1451-
LocalVersionSlice::Sentinel => String::from("[max]"),
1446+
LocalVersionSlice::Segments(segments) => {
1447+
for (i, segment) in segments.iter().enumerate() {
1448+
if i > 0 {
1449+
write!(f, ".")?;
1450+
}
1451+
write!(f, "{segment}")?;
1452+
}
1453+
Ok(())
1454+
}
1455+
LocalVersionSlice::Max => write!(f, "[max]"),
14521456
}
14531457
}
14541458
}
@@ -1462,18 +1466,18 @@ impl PartialOrd for LocalVersionSlice<'_> {
14621466
impl Ord for LocalVersionSlice<'_> {
14631467
fn cmp(&self, other: &Self) -> Ordering {
14641468
match (self, other) {
1465-
(LocalVersionSlice::Actual(lv1), LocalVersionSlice::Actual(lv2)) => lv1.cmp(lv2),
1466-
(LocalVersionSlice::Actual(_), LocalVersionSlice::Sentinel) => Ordering::Less,
1467-
(LocalVersionSlice::Sentinel, LocalVersionSlice::Actual(_)) => Ordering::Greater,
1468-
(LocalVersionSlice::Sentinel, LocalVersionSlice::Sentinel) => Ordering::Equal,
1469+
(LocalVersionSlice::Segments(lv1), LocalVersionSlice::Segments(lv2)) => lv1.cmp(lv2),
1470+
(LocalVersionSlice::Segments(_), LocalVersionSlice::Max) => Ordering::Less,
1471+
(LocalVersionSlice::Max, LocalVersionSlice::Segments(_)) => Ordering::Greater,
1472+
(LocalVersionSlice::Max, LocalVersionSlice::Max) => Ordering::Equal,
14691473
}
14701474
}
14711475
}
14721476

14731477
impl LocalVersionSlice<'_> {
14741478
/// Whether the local version is absent
14751479
pub fn is_empty(&self) -> bool {
1476-
matches!(self, Self::Actual(&[]))
1480+
matches!(self, Self::Segments(&[]))
14771481
}
14781482
}
14791483

@@ -1924,7 +1928,7 @@ impl<'a> Parser<'a> {
19241928
.with_pre(self.pre)
19251929
.with_post(self.post)
19261930
.with_dev(self.dev)
1927-
.with_local(LocalVersion::Actual(self.local));
1931+
.with_local(LocalVersion::Segments(self.local));
19281932
VersionPattern {
19291933
version,
19301934
wildcard: self.wildcard,

crates/uv-pep440/src/version_ranges.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ impl From<VersionSpecifier> for Ranges<Version> {
2626
let VersionSpecifier { operator, version } = specifier;
2727
match operator {
2828
Operator::Equal => match version.local() {
29-
LocalVersionSlice::Actual(&[]) => {
29+
LocalVersionSlice::Segments(&[]) => {
3030
let low = version;
3131
let high = low.clone().with_local(LocalVersion::Max);
3232
Ranges::between(low, high)
3333
}
34-
LocalVersionSlice::Actual(_) => Ranges::singleton(version),
35-
LocalVersionSlice::Sentinel => unreachable!(
34+
LocalVersionSlice::Segments(_) => Ranges::singleton(version),
35+
LocalVersionSlice::Max => unreachable!(
3636
"found `LocalVersionSlice::Sentinel`, which should be an internal-only value"
3737
),
3838
},

crates/uv-pep440/src/version_specifier.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ impl std::fmt::Display for VersionSpecifierBuildError {
652652
operator: ref op,
653653
ref version,
654654
} => {
655-
let local = version.local().local_identifier_string();
655+
let local = version.local();
656656
write!(
657657
f,
658658
"Operator {op} is incompatible with versions \

crates/uv-python/src/discovery.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2096,7 +2096,7 @@ impl FromStr for VersionRequest {
20962096
return Err(Error::InvalidVersionRequest(s.to_string()));
20972097
}
20982098

2099-
let uv_pep440::LocalVersionSlice::Actual([uv_pep440::LocalSegment::String(local)]) =
2099+
let uv_pep440::LocalVersionSlice::Segments([uv_pep440::LocalSegment::String(local)]) =
21002100
version.local()
21012101
else {
21022102
return Err(Error::InvalidVersionRequest(s.to_string()));

crates/uv-resolver/src/error.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -237,65 +237,65 @@ impl NoSolutionError {
237237
(Bound::Unbounded, Bound::Unbounded) => {}
238238
(Bound::Unbounded, Bound::Included(v)) => {
239239
// `<=1.0.0+[max]` is equivalent to `<=1.0.0`
240-
if v.local() == LocalVersionSlice::Sentinel {
240+
if v.local() == LocalVersionSlice::Max {
241241
*upper = Bound::Included(v.clone().without_local());
242242
}
243243
}
244244
(Bound::Unbounded, Bound::Excluded(v)) => {
245245
// `<1.0.0+[max]` is equivalent to `<1.0.0`
246-
if v.local() == LocalVersionSlice::Sentinel {
246+
if v.local() == LocalVersionSlice::Max {
247247
*upper = Bound::Excluded(v.clone().without_local());
248248
}
249249
}
250250
(Bound::Included(v), Bound::Unbounded) => {
251251
// `>=1.0.0+[max]` is equivalent to `>1.0.0`
252-
if v.local() == LocalVersionSlice::Sentinel {
252+
if v.local() == LocalVersionSlice::Max {
253253
*lower = Bound::Excluded(v.clone().without_local());
254254
}
255255
}
256256
(Bound::Included(v), Bound::Included(b)) => {
257257
// `>=1.0.0+[max]` is equivalent to `>1.0.0`
258-
if v.local() == LocalVersionSlice::Sentinel {
258+
if v.local() == LocalVersionSlice::Max {
259259
*lower = Bound::Excluded(v.clone().without_local());
260260
}
261261
// `<=1.0.0+[max]` is equivalent to `<=1.0.0`
262-
if b.local() == LocalVersionSlice::Sentinel {
262+
if b.local() == LocalVersionSlice::Max {
263263
*upper = Bound::Included(b.clone().without_local());
264264
}
265265
}
266266
(Bound::Included(v), Bound::Excluded(b)) => {
267267
// `>=1.0.0+[max]` is equivalent to `>1.0.0`
268-
if v.local() == LocalVersionSlice::Sentinel {
268+
if v.local() == LocalVersionSlice::Max {
269269
*lower = Bound::Excluded(v.clone().without_local());
270270
}
271271
// `<1.0.0+[max]` is equivalent to `<1.0.0`
272-
if b.local() == LocalVersionSlice::Sentinel {
272+
if b.local() == LocalVersionSlice::Max {
273273
*upper = Bound::Included(b.clone().without_local());
274274
}
275275
}
276276
(Bound::Excluded(v), Bound::Unbounded) => {
277277
// `>1.0.0+[max]` is equivalent to `>1.0.0`
278-
if v.local() == LocalVersionSlice::Sentinel {
278+
if v.local() == LocalVersionSlice::Max {
279279
*lower = Bound::Excluded(v.clone().without_local());
280280
}
281281
}
282282
(Bound::Excluded(v), Bound::Included(b)) => {
283283
// `>1.0.0+[max]` is equivalent to `>1.0.0`
284-
if v.local() == LocalVersionSlice::Sentinel {
284+
if v.local() == LocalVersionSlice::Max {
285285
*lower = Bound::Excluded(v.clone().without_local());
286286
}
287287
// `<=1.0.0+[max]` is equivalent to `<=1.0.0`
288-
if b.local() == LocalVersionSlice::Sentinel {
288+
if b.local() == LocalVersionSlice::Max {
289289
*upper = Bound::Included(b.clone().without_local());
290290
}
291291
}
292292
(Bound::Excluded(v), Bound::Excluded(b)) => {
293293
// `>1.0.0+[max]` is equivalent to `>1.0.0`
294-
if v.local() == LocalVersionSlice::Sentinel {
294+
if v.local() == LocalVersionSlice::Max {
295295
*lower = Bound::Excluded(v.clone().without_local());
296296
}
297297
// `<1.0.0+[max]` is equivalent to `<1.0.0`
298-
if b.local() == LocalVersionSlice::Sentinel {
298+
if b.local() == LocalVersionSlice::Max {
299299
*upper = Bound::Excluded(b.clone().without_local());
300300
}
301301
}
@@ -309,10 +309,10 @@ impl NoSolutionError {
309309
let (Bound::Excluded(lower), Bound::Excluded(upper)) = (lower, upper) else {
310310
return false;
311311
};
312-
if lower.local() == LocalVersionSlice::Sentinel {
312+
if lower.local() == LocalVersionSlice::Max {
313313
return false;
314314
}
315-
if upper.local() != LocalVersionSlice::Sentinel {
315+
if upper.local() != LocalVersionSlice::Max {
316316
return false;
317317
}
318318
*lower == upper.clone().without_local()

0 commit comments

Comments
 (0)