@@ -16,11 +16,13 @@ use serde::{Deserialize, Serialize};
16
16
use serde_untagged:: UntaggedEnumVisitor ;
17
17
18
18
use crate :: core:: PackageIdSpec ;
19
- use crate :: core:: PartialVersion ;
20
- use crate :: core:: PartialVersionError ;
21
19
use crate :: restricted_names;
22
20
21
+ mod rust_version;
22
+
23
23
pub use crate :: restricted_names:: NameValidationError ;
24
+ pub use rust_version:: RustVersion ;
25
+ pub use rust_version:: RustVersionError ;
24
26
25
27
/// This type is used to deserialize `Cargo.toml` files.
26
28
#[ derive( Debug , Deserialize , Serialize ) ]
@@ -1399,79 +1401,6 @@ pub enum TomlLintLevel {
1399
1401
Allow ,
1400
1402
}
1401
1403
1402
- #[ derive( PartialEq , Eq , PartialOrd , Ord , Hash , Clone , Debug , serde:: Serialize ) ]
1403
- #[ serde( transparent) ]
1404
- pub struct RustVersion ( PartialVersion ) ;
1405
-
1406
- impl std:: ops:: Deref for RustVersion {
1407
- type Target = PartialVersion ;
1408
-
1409
- fn deref ( & self ) -> & Self :: Target {
1410
- & self . 0
1411
- }
1412
- }
1413
-
1414
- impl std:: str:: FromStr for RustVersion {
1415
- type Err = RustVersionError ;
1416
-
1417
- fn from_str ( value : & str ) -> Result < Self , Self :: Err > {
1418
- let partial = value. parse :: < PartialVersion > ( ) ;
1419
- let partial = partial. map_err ( RustVersionErrorKind :: PartialVersion ) ?;
1420
- partial. try_into ( )
1421
- }
1422
- }
1423
-
1424
- impl TryFrom < PartialVersion > for RustVersion {
1425
- type Error = RustVersionError ;
1426
-
1427
- fn try_from ( partial : PartialVersion ) -> Result < Self , Self :: Error > {
1428
- if partial. pre . is_some ( ) {
1429
- return Err ( RustVersionErrorKind :: Prerelease . into ( ) ) ;
1430
- }
1431
- if partial. build . is_some ( ) {
1432
- return Err ( RustVersionErrorKind :: BuildMetadata . into ( ) ) ;
1433
- }
1434
- Ok ( Self ( partial) )
1435
- }
1436
- }
1437
-
1438
- impl < ' de > serde:: Deserialize < ' de > for RustVersion {
1439
- fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
1440
- where
1441
- D : serde:: Deserializer < ' de > ,
1442
- {
1443
- UntaggedEnumVisitor :: new ( )
1444
- . expecting ( "SemVer version" )
1445
- . string ( |value| value. parse ( ) . map_err ( serde:: de:: Error :: custom) )
1446
- . deserialize ( deserializer)
1447
- }
1448
- }
1449
-
1450
- impl Display for RustVersion {
1451
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1452
- self . 0 . fmt ( f)
1453
- }
1454
- }
1455
-
1456
- /// Error parsing a [`RustVersion`].
1457
- #[ derive( Debug , thiserror:: Error ) ]
1458
- #[ error( transparent) ]
1459
- pub struct RustVersionError ( #[ from] RustVersionErrorKind ) ;
1460
-
1461
- /// Non-public error kind for [`RustVersionError`].
1462
- #[ non_exhaustive]
1463
- #[ derive( Debug , thiserror:: Error ) ]
1464
- enum RustVersionErrorKind {
1465
- #[ error( "unexpected prerelease field, expected a version like \" 1.32\" " ) ]
1466
- Prerelease ,
1467
-
1468
- #[ error( "unexpected build field, expected a version like \" 1.32\" " ) ]
1469
- BuildMetadata ,
1470
-
1471
- #[ error( transparent) ]
1472
- PartialVersion ( #[ from] PartialVersionError ) ,
1473
- }
1474
-
1475
1404
#[ derive( Copy , Clone , Debug ) ]
1476
1405
pub struct InvalidCargoFeatures { }
1477
1406
0 commit comments