@@ -72,7 +72,7 @@ pub struct Config {
72
72
pub book : BookConfig ,
73
73
/// Information about the build environment.
74
74
pub build : BuildConfig ,
75
- /// Information passed to the Rust playground
75
+ /// Information about Rust language support.
76
76
pub rust : RustConfig ,
77
77
rest : Value ,
78
78
}
@@ -340,6 +340,7 @@ impl<'de> Deserialize<'de> for Config {
340
340
impl Serialize for Config {
341
341
fn serialize < S : Serializer > ( & self , s : S ) -> std:: result:: Result < S :: Ok , S :: Error > {
342
342
use serde:: ser:: Error ;
343
+ // TODO: This should probably be removed and use a derive instead.
343
344
344
345
let mut table = self . rest . clone ( ) ;
345
346
@@ -349,8 +350,10 @@ impl Serialize for Config {
349
350
return Err ( S :: Error :: custom ( "Unable to serialize the BookConfig" ) ) ;
350
351
}
351
352
} ;
353
+ let rust_config = Value :: try_from ( & self . rust ) . expect ( "should always be serializable" ) ;
352
354
353
355
table. insert ( "book" , book_config) . expect ( "unreachable" ) ;
356
+ table. insert ( "rust" , rust_config) . expect ( "unreachable" ) ;
354
357
table. serialize ( s)
355
358
}
356
359
}
@@ -449,55 +452,17 @@ pub struct RustConfig {
449
452
pub edition : Option < RustEdition > ,
450
453
}
451
454
452
- #[ derive( Debug , Copy , Clone , PartialEq ) ]
455
+ #[ derive( Debug , Copy , Clone , PartialEq , Serialize , Deserialize ) ]
453
456
/// Rust edition to use for the code.
454
457
pub enum RustEdition {
455
458
/// The 2018 edition of Rust
459
+ #[ serde( rename = "2018" ) ]
456
460
E2018 ,
457
461
/// The 2015 edition of Rust
462
+ #[ serde( rename = "2015" ) ]
458
463
E2015 ,
459
464
}
460
465
461
- impl Serialize for RustEdition {
462
- fn serialize < S > ( & self , serializer : S ) -> std:: result:: Result < S :: Ok , S :: Error >
463
- where
464
- S : Serializer ,
465
- {
466
- match self {
467
- RustEdition :: E2015 => serializer. serialize_str ( "2015" ) ,
468
- RustEdition :: E2018 => serializer. serialize_str ( "2018" ) ,
469
- }
470
- }
471
- }
472
-
473
- impl < ' de > Deserialize < ' de > for RustEdition {
474
- fn deserialize < D > ( de : D ) -> std:: result:: Result < Self , D :: Error >
475
- where
476
- D : Deserializer < ' de > ,
477
- {
478
- use serde:: de:: Error ;
479
-
480
- let raw = Value :: deserialize ( de) ?;
481
-
482
- let edition = match raw {
483
- Value :: String ( s) => s,
484
- _ => {
485
- return Err ( D :: Error :: custom ( "Rust edition should be a string" ) ) ;
486
- }
487
- } ;
488
-
489
- let edition = match edition. as_str ( ) {
490
- "2018" => RustEdition :: E2018 ,
491
- "2015" => RustEdition :: E2015 ,
492
- e => {
493
- return Err ( D :: Error :: custom ( format ! ( "Unknown Rust edition: {}" , e) ) ) ;
494
- }
495
- } ;
496
-
497
- Ok ( edition)
498
- }
499
- }
500
-
501
466
/// Configuration for the HTML renderer.
502
467
#[ derive( Debug , Clone , Default , PartialEq , Serialize , Deserialize ) ]
503
468
#[ serde( default , rename_all = "kebab-case" ) ]
0 commit comments