@@ -513,6 +513,8 @@ pub struct Playpen {
513513 pub copy_js : bool ,
514514 /// Display line numbers on playpen snippets. Default: `false`.
515515 pub line_numbers : bool ,
516+ /// Rust edition to use for the code. Default: `2015`.
517+ pub edition : RustEdition ,
516518}
517519
518520impl Default for Playpen {
@@ -522,10 +524,66 @@ impl Default for Playpen {
522524 copyable : true ,
523525 copy_js : true ,
524526 line_numbers : false ,
527+ edition : RustEdition :: E2015 ,
525528 }
526529 }
527530}
528531
532+ #[ derive( Debug , Clone , PartialEq ) ]
533+ /// The edition of Rust used in a playpen code snippet
534+ pub enum RustEdition {
535+ /// The 2018 edition of Rust
536+ E2018 ,
537+ /// The 2015 edition of Rust
538+ E2015 ,
539+ }
540+
541+ impl Default for RustEdition {
542+ fn default ( ) -> Self {
543+ RustEdition :: E2015
544+ }
545+ }
546+
547+ impl Serialize for RustEdition {
548+ fn serialize < S > ( & self , serializer : S ) -> std:: result:: Result < S :: Ok , S :: Error >
549+ where
550+ S : Serializer ,
551+ {
552+ match self {
553+ RustEdition :: E2015 => serializer. serialize_str ( "2015" ) ,
554+ RustEdition :: E2018 => serializer. serialize_str ( "2018" ) ,
555+ }
556+ }
557+ }
558+
559+ impl < ' de > Deserialize < ' de > for RustEdition {
560+ fn deserialize < D > ( de : D ) -> std:: result:: Result < Self , D :: Error >
561+ where
562+ D : Deserializer < ' de > ,
563+ {
564+ use serde:: de:: Error ;
565+
566+ let raw = Value :: deserialize ( de) ?;
567+
568+ let edition = match raw {
569+ Value :: String ( s) => s,
570+ _ => {
571+ return Err ( D :: Error :: custom ( "Rust edition should be a string" ) ) ;
572+ }
573+ } ;
574+
575+ let edition = match edition. as_str ( ) {
576+ "2018" => RustEdition :: E2018 ,
577+ "2015" => RustEdition :: E2015 ,
578+ _ => {
579+ return Err ( D :: Error :: custom ( "Unknown Rust edition" ) ) ;
580+ }
581+ } ;
582+
583+ Ok ( edition)
584+ }
585+ }
586+
529587/// Configuration of the search functionality of the HTML renderer.
530588#[ derive( Debug , Clone , PartialEq , Serialize , Deserialize ) ]
531589#[ serde( default , rename_all = "kebab-case" ) ]
@@ -630,6 +688,7 @@ mod tests {
630688 [output.html.playpen]
631689 editable = true
632690 editor = "ace"
691+ edition = "2018"
633692
634693 [preprocessor.first]
635694
@@ -658,6 +717,7 @@ mod tests {
658717 copyable : true ,
659718 copy_js : true ,
660719 line_numbers : false ,
720+ edition : RustEdition :: E2018 ,
661721 } ;
662722 let html_should_be = HtmlConfig {
663723 curly_quotes : true ,
0 commit comments