@@ -8,17 +8,17 @@ use crate::{embedded::EMBEDDED_FILES, exercise::RunnableExercise};
88#[ derive( Deserialize ) ]
99pub struct ExerciseInfo {
1010 /// Exercise's unique name.
11- pub name : String ,
11+ pub name : & ' static str ,
1212 /// Exercise's directory name inside the `exercises/` directory.
13- pub dir : Option < String > ,
13+ pub dir : Option < & ' static str > ,
1414 /// Run `cargo test` on the exercise.
1515 #[ serde( default = "default_true" ) ]
1616 pub test : bool ,
1717 /// Deny all Clippy warnings.
1818 #[ serde( default ) ]
1919 pub strict_clippy : bool ,
2020 /// The exercise's hint to be shown to the user on request.
21- pub hint : String ,
21+ pub hint : & ' static str ,
2222 /// The exercise is already solved. Ignore it when checking that all exercises are unsolved.
2323 #[ serde( default ) ]
2424 pub skip_check_unsolved : bool ,
@@ -31,7 +31,7 @@ const fn default_true() -> bool {
3131impl ExerciseInfo {
3232 /// Path to the exercise file starting with the `exercises/` directory.
3333 pub fn path ( & self ) -> String {
34- let mut path = if let Some ( dir) = & self . dir {
34+ let mut path = if let Some ( dir) = self . dir {
3535 // 14 = 10 + 1 + 3
3636 // exercises/ + / + .rs
3737 let mut path = String :: with_capacity ( 14 + dir. len ( ) + self . name . len ( ) ) ;
@@ -47,7 +47,7 @@ impl ExerciseInfo {
4747 path
4848 } ;
4949
50- path. push_str ( & self . name ) ;
50+ path. push_str ( self . name ) ;
5151 path. push_str ( ".rs" ) ;
5252
5353 path
@@ -57,12 +57,12 @@ impl ExerciseInfo {
5757impl RunnableExercise for ExerciseInfo {
5858 #[ inline]
5959 fn name ( & self ) -> & str {
60- & self . name
60+ self . name
6161 }
6262
6363 #[ inline]
6464 fn dir ( & self ) -> Option < & str > {
65- self . dir . as_deref ( )
65+ self . dir
6666 }
6767
6868 #[ inline]
@@ -82,9 +82,9 @@ pub struct InfoFile {
8282 /// For possible breaking changes in the future for community exercises.
8383 pub format_version : u8 ,
8484 /// Shown to users when starting with the exercises.
85- pub welcome_message : Option < String > ,
85+ pub welcome_message : Option < & ' static str > ,
8686 /// Shown to users after finishing all exercises.
87- pub final_message : Option < String > ,
87+ pub final_message : Option < & ' static str > ,
8888 /// List of all exercises.
8989 pub exercises : Vec < ExerciseInfo > ,
9090}
@@ -95,7 +95,8 @@ impl InfoFile {
9595 pub fn parse ( ) -> Result < Self > {
9696 // Read a local `info.toml` if it exists.
9797 let slf = match fs:: read_to_string ( "info.toml" ) {
98- Ok ( file_content) => toml:: de:: from_str :: < Self > ( & file_content)
98+ // Leaking is fine since `InfoFile` is used until the end of the program.
99+ Ok ( file_content) => toml:: de:: from_str :: < Self > ( file_content. leak ( ) )
99100 . context ( "Failed to parse the `info.toml` file" ) ?,
100101 Err ( e) => {
101102 if e. kind ( ) == ErrorKind :: NotFound {
0 commit comments