@@ -534,7 +534,7 @@ impl Version {
534
534
if value. is_empty ( ) {
535
535
self . without_local ( )
536
536
} else {
537
- self . make_full ( ) . local = LocalVersion :: Actual ( value) ;
537
+ self . make_full ( ) . local = LocalVersion :: Segments ( value) ;
538
538
self
539
539
}
540
540
}
@@ -544,7 +544,7 @@ impl Version {
544
544
#[ must_use]
545
545
pub fn with_local ( mut self , value : LocalVersion ) -> Self {
546
546
match value {
547
- LocalVersion :: Actual ( segments) => self . with_local_segments ( segments) ,
547
+ LocalVersion :: Segments ( segments) => self . with_local_segments ( segments) ,
548
548
LocalVersion :: Max => {
549
549
self . make_full ( ) . local = value;
550
550
self
@@ -628,7 +628,7 @@ impl Version {
628
628
pre : small. pre ( ) ,
629
629
post : small. post ( ) ,
630
630
dev : small. dev ( ) ,
631
- local : LocalVersion :: Actual ( vec ! [ ] ) ,
631
+ local : LocalVersion :: Segments ( vec ! [ ] ) ,
632
632
} ;
633
633
* self = Self {
634
634
inner : Arc :: new ( VersionInner :: Full { full } ) ,
@@ -726,10 +726,10 @@ impl std::fmt::Display for Version {
726
726
String :: new ( )
727
727
} else {
728
728
match self . local ( ) {
729
- LocalVersionSlice :: Actual ( _) => {
730
- format ! ( "+{}" , self . local( ) . local_identifier_string ( ) )
729
+ LocalVersionSlice :: Segments ( _) => {
730
+ format ! ( "+{}" , self . local( ) )
731
731
}
732
- LocalVersionSlice :: Sentinel => String :: new ( ) ,
732
+ LocalVersionSlice :: Max => String :: new ( ) ,
733
733
}
734
734
} ;
735
735
write ! ( f, "{epoch}{release}{pre}{post}{dev}{local}" )
@@ -849,7 +849,7 @@ impl FromStr for Version {
849
849
/// `min, .devN, aN, bN, rcN, <no suffix>, .postN, max`.
850
850
/// Its representation is thus:
851
851
/// * 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,
853
853
/// no-suffix or post releases, respectively. `min` is a special version that
854
854
/// does not exist in PEP 440, but is used here to represent the smallest
855
855
/// possible version, preceding any `dev`, `pre`, `post` or releases. `max` is
@@ -1178,7 +1178,7 @@ impl VersionSmall {
1178
1178
fn local ( & self ) -> LocalVersionSlice {
1179
1179
// A "small" version is never used if the version has a non-zero number
1180
1180
// of local segments.
1181
- LocalVersionSlice :: Actual ( & [ ] )
1181
+ LocalVersionSlice :: Segments ( & [ ] )
1182
1182
}
1183
1183
1184
1184
#[ inline]
@@ -1200,13 +1200,13 @@ impl VersionSmall {
1200
1200
1201
1201
#[ inline]
1202
1202
fn suffix_version ( & self ) -> u64 {
1203
- self . repr & 0x001F_FFFF
1203
+ self . repr & Self :: SUFFIX_MAX_VERSION
1204
1204
}
1205
1205
1206
1206
#[ inline]
1207
1207
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 ;
1210
1210
self . repr |= value;
1211
1211
}
1212
1212
}
@@ -1404,51 +1404,55 @@ impl std::fmt::Display for Prerelease {
1404
1404
#[ cfg_attr( feature = "rkyv" , rkyv( derive( Debug , Eq , PartialEq , PartialOrd , Ord ) ) ) ]
1405
1405
pub enum LocalVersion {
1406
1406
/// A sequence of local segments.
1407
- Actual ( Vec < LocalSegment > ) ,
1407
+ Segments ( Vec < LocalSegment > ) ,
1408
1408
/// An internal-only value that compares greater to all other local versions.
1409
1409
Max ,
1410
1410
}
1411
1411
1412
1412
/// Like [`LocalVersion`], but using a slice
1413
1413
#[ derive( Eq , PartialEq , Debug , Clone , Hash ) ]
1414
1414
pub enum LocalVersionSlice < ' a > {
1415
- /// Like [`LocalVersion::Actual `]
1416
- Actual ( & ' a [ LocalSegment ] ) ,
1415
+ /// Like [`LocalVersion::Segments `]
1416
+ Segments ( & ' a [ LocalSegment ] ) ,
1417
1417
/// Like [`LocalVersion::Sentinel`]
1418
- Sentinel ,
1418
+ Max ,
1419
1419
}
1420
1420
1421
1421
impl LocalVersion {
1422
1422
/// Convert the local version segments into a slice.
1423
1423
pub fn as_slice ( & self ) -> LocalVersionSlice < ' _ > {
1424
1424
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 ,
1427
1427
}
1428
1428
}
1429
1429
1430
1430
/// Clear the local version segments, if they exist.
1431
1431
pub fn clear ( & mut self ) {
1432
1432
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 ( ) ) ,
1435
1435
}
1436
1436
}
1437
1437
}
1438
1438
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 {
1445
1445
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]" ) ,
1452
1456
}
1453
1457
}
1454
1458
}
@@ -1462,18 +1466,18 @@ impl PartialOrd for LocalVersionSlice<'_> {
1462
1466
impl Ord for LocalVersionSlice < ' _ > {
1463
1467
fn cmp ( & self , other : & Self ) -> Ordering {
1464
1468
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 ,
1469
1473
}
1470
1474
}
1471
1475
}
1472
1476
1473
1477
impl LocalVersionSlice < ' _ > {
1474
1478
/// Whether the local version is absent
1475
1479
pub fn is_empty ( & self ) -> bool {
1476
- matches ! ( self , Self :: Actual ( & [ ] ) )
1480
+ matches ! ( self , Self :: Segments ( & [ ] ) )
1477
1481
}
1478
1482
}
1479
1483
@@ -1924,7 +1928,7 @@ impl<'a> Parser<'a> {
1924
1928
. with_pre ( self . pre )
1925
1929
. with_post ( self . post )
1926
1930
. with_dev ( self . dev )
1927
- . with_local ( LocalVersion :: Actual ( self . local ) ) ;
1931
+ . with_local ( LocalVersion :: Segments ( self . local ) ) ;
1928
1932
VersionPattern {
1929
1933
version,
1930
1934
wildcard : self . wildcard ,
0 commit comments