@@ -979,6 +979,22 @@ impl StringOrVec {
979
979
}
980
980
}
981
981
982
+ #[ derive( Clone , Debug , Deserialize , Serialize , Eq , PartialEq ) ]
983
+ #[ serde( untagged, expecting = "expected a string or an integer" ) ]
984
+ pub enum StringOrI64 {
985
+ String ( String ) ,
986
+ I64 ( i64 ) ,
987
+ }
988
+
989
+ impl Display for StringOrI64 {
990
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
991
+ match self {
992
+ StringOrI64 :: String ( s) => f. write_str ( s) ,
993
+ StringOrI64 :: I64 ( v) => write ! ( f, "{v}" ) ,
994
+ }
995
+ }
996
+ }
997
+
982
998
#[ derive( Clone , Debug , Deserialize , Serialize , Eq , PartialEq ) ]
983
999
#[ serde( untagged, expecting = "expected a boolean or a string" ) ]
984
1000
pub enum StringOrBool {
@@ -1262,6 +1278,50 @@ impl TomlWorkspaceDependency {
1262
1278
//. This already has a `Deserialize` impl from version_trim_whitespace
1263
1279
type MaybeWorkspaceSemverVersion = MaybeWorkspace < semver:: Version , TomlWorkspaceField > ;
1264
1280
1281
+ type MaybeWorkspaceStringOrI64 = MaybeWorkspace < StringOrI64 , TomlWorkspaceField > ;
1282
+ impl < ' de > de:: Deserialize < ' de > for MaybeWorkspaceStringOrI64 {
1283
+ fn deserialize < D > ( d : D ) -> Result < Self , D :: Error >
1284
+ where
1285
+ D : de:: Deserializer < ' de > ,
1286
+ {
1287
+ struct Visitor ;
1288
+
1289
+ impl < ' de > de:: Visitor < ' de > for Visitor {
1290
+ type Value = MaybeWorkspaceStringOrI64 ;
1291
+
1292
+ fn expecting ( & self , f : & mut fmt:: Formatter < ' _ > ) -> Result < ( ) , std:: fmt:: Error > {
1293
+ f. write_str ( "a string, integer or workspace" )
1294
+ }
1295
+
1296
+ fn visit_i64 < E > ( self , value : i64 ) -> Result < Self :: Value , E >
1297
+ where
1298
+ E : de:: Error ,
1299
+ {
1300
+ let int = de:: value:: I64Deserializer :: new ( value) ;
1301
+ StringOrI64 :: deserialize ( int) . map ( MaybeWorkspace :: Defined )
1302
+ }
1303
+
1304
+ fn visit_string < E > ( self , value : String ) -> Result < Self :: Value , E >
1305
+ where
1306
+ E : de:: Error ,
1307
+ {
1308
+ let string = de:: value:: StringDeserializer :: new ( value) ;
1309
+ StringOrI64 :: deserialize ( string) . map ( MaybeWorkspace :: Defined )
1310
+ }
1311
+
1312
+ fn visit_map < V > ( self , map : V ) -> Result < Self :: Value , V :: Error >
1313
+ where
1314
+ V : de:: MapAccess < ' de > ,
1315
+ {
1316
+ let mvd = de:: value:: MapAccessDeserializer :: new ( map) ;
1317
+ TomlWorkspaceField :: deserialize ( mvd) . map ( MaybeWorkspace :: Workspace )
1318
+ }
1319
+ }
1320
+
1321
+ d. deserialize_any ( Visitor )
1322
+ }
1323
+ }
1324
+
1265
1325
type MaybeWorkspaceString = MaybeWorkspace < String , TomlWorkspaceField > ;
1266
1326
impl < ' de > de:: Deserialize < ' de > for MaybeWorkspaceString {
1267
1327
fn deserialize < D > ( d : D ) -> Result < Self , D :: Error >
@@ -1501,7 +1561,7 @@ impl WorkspaceInherit for TomlWorkspaceField {
1501
1561
#[ derive( Deserialize , Serialize , Clone , Debug ) ]
1502
1562
#[ serde( rename_all = "kebab-case" ) ]
1503
1563
pub struct TomlPackage {
1504
- edition : Option < MaybeWorkspaceString > ,
1564
+ edition : Option < MaybeWorkspaceStringOrI64 > ,
1505
1565
rust_version : Option < MaybeWorkspaceString > ,
1506
1566
name : InternedString ,
1507
1567
#[ serde( deserialize_with = "version_trim_whitespace" ) ]
@@ -1583,7 +1643,7 @@ pub struct InheritableFields {
1583
1643
license_file : Option < String > ,
1584
1644
repository : Option < String > ,
1585
1645
publish : Option < VecStringOrBool > ,
1586
- edition : Option < String > ,
1646
+ edition : Option < StringOrI64 > ,
1587
1647
badges : Option < BTreeMap < String , BTreeMap < String , String > > > ,
1588
1648
exclude : Option < Vec < String > > ,
1589
1649
include : Option < Vec < String > > ,
@@ -1730,7 +1790,7 @@ impl InheritableFields {
1730
1790
)
1731
1791
}
1732
1792
1733
- pub fn edition ( & self ) -> CargoResult < String > {
1793
+ pub fn edition ( & self ) -> CargoResult < StringOrI64 > {
1734
1794
self . edition . clone ( ) . map_or (
1735
1795
Err ( anyhow ! ( "`workspace.package.edition` was not defined" ) ) ,
1736
1796
|d| Ok ( d) ,
@@ -1817,7 +1877,7 @@ impl TomlManifest {
1817
1877
. edition
1818
1878
. as_ref ( )
1819
1879
. and_then ( |e| e. as_defined ( ) )
1820
- . map ( |e| Edition :: from_str ( e ) )
1880
+ . map ( |e| Edition :: from_str ( & e . to_string ( ) ) )
1821
1881
. unwrap_or ( Ok ( Edition :: Edition2015 ) )
1822
1882
. map ( |e| e. default_resolve_behavior ( ) )
1823
1883
} ) ?;
@@ -2129,9 +2189,12 @@ impl TomlManifest {
2129
2189
let edition = if let Some ( edition) = package. edition . clone ( ) {
2130
2190
let edition: Edition = edition
2131
2191
. resolve ( "edition" , || inherit ( ) ?. edition ( ) ) ?
2192
+ . to_string ( )
2132
2193
. parse ( )
2133
2194
. with_context ( || "failed to parse the `edition` key" ) ?;
2134
- package. edition = Some ( MaybeWorkspace :: Defined ( edition. to_string ( ) ) ) ;
2195
+ package. edition = Some ( MaybeWorkspace :: Defined ( StringOrI64 :: String (
2196
+ edition. to_string ( ) ,
2197
+ ) ) ) ;
2135
2198
edition
2136
2199
} else {
2137
2200
Edition :: Edition2015
0 commit comments