diff --git a/src/app_state.rs b/src/app_state.rs index 71a4fbbf..765425a9 100644 --- a/src/app_state.rs +++ b/src/app_state.rs @@ -83,12 +83,6 @@ impl AppState { let mut exercises = exercise_infos .into_iter() .map(|exercise_info| { - // Leaking to be able to borrow in the watch mode `Table`. - // Leaking is not a problem because the `AppState` instance lives until - // the end of the program. - let path = exercise_info.path().leak(); - let hint = exercise_info.hint.trim_ascii(); - let canonical_path = dir_canonical_path.as_deref().map(|dir_canonical_path| { let mut canonical_path; if let Some(dir) = exercise_info.dir { @@ -114,11 +108,11 @@ impl AppState { Exercise { dir: exercise_info.dir, name: exercise_info.name, - path, + path: exercise_info.path(), canonical_path, test: exercise_info.test, strict_clippy: exercise_info.strict_clippy, - hint, + hint: exercise_info.hint.trim_ascii(), // Updated below. done: false, } @@ -342,12 +336,12 @@ impl AppState { Ok(()) } - pub fn reset_current_exercise(&mut self) -> Result<&'static str> { + pub fn reset_current_exercise(&mut self) -> Result<&str> { self.set_pending(self.current_exercise_ind)?; let exercise = self.current_exercise(); - self.reset(self.current_exercise_ind, exercise.path)?; + self.reset(self.current_exercise_ind, &exercise.path)?; - Ok(exercise.path) + Ok(&exercise.path) } // Reset the exercise by index and return its name. @@ -358,7 +352,7 @@ impl AppState { self.set_pending(exercise_ind)?; let exercise = &self.exercises[exercise_ind]; - self.reset(exercise_ind, exercise.path)?; + self.reset(exercise_ind, &exercise.path)?; Ok(exercise.name) } @@ -600,7 +594,7 @@ mod tests { Exercise { dir: None, name: "0", - path: "exercises/0.rs", + path: String::from("exercises/0.rs"), canonical_path: None, test: false, strict_clippy: false, diff --git a/src/exercise.rs b/src/exercise.rs index a0596b5b..ee1f42f9 100644 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -69,7 +69,7 @@ pub struct Exercise { pub dir: Option<&'static str>, pub name: &'static str, /// Path of the exercise file starting with the `exercises/` directory. - pub path: &'static str, + pub path: String, pub canonical_path: Option, pub test: bool, pub strict_clippy: bool, @@ -85,9 +85,9 @@ impl Exercise { ) -> io::Result<()> { file_path(writer, Color::Blue, |writer| { if emit_file_links && let Some(canonical_path) = self.canonical_path.as_deref() { - terminal_file_link(writer, self.path, canonical_path) + terminal_file_link(writer, &self.path, canonical_path) } else { - writer.write_str(self.path) + writer.write_str(&self.path) } }) } diff --git a/src/info_file.rs b/src/info_file.rs index 8a90fcca..23df0d16 100644 --- a/src/info_file.rs +++ b/src/info_file.rs @@ -95,7 +95,7 @@ impl InfoFile { pub fn parse() -> Result { // Read a local `info.toml` if it exists. let slf = match fs::read_to_string("info.toml") { - // Leaking is fine since `InfoFile` is used until the end of the program. + // Leaking is fine since the info file is used until the end of the program. Ok(file_content) => toml::de::from_str::(file_content.leak()) .context("Failed to parse the `info.toml` file")?, Err(e) => { diff --git a/src/list/state.rs b/src/list/state.rs index 4fd1301d..55ccb4c9 100644 --- a/src/list/state.rs +++ b/src/list/state.rs @@ -366,11 +366,11 @@ impl<'a> ListState<'a> { let exercise_ind = self.selected_to_exercise_ind(selected)?; let exercise_name = self.app_state.reset_exercise_by_ind(exercise_ind)?; - self.update_rows(); write!( self.message, "The exercise `{exercise_name}` has been reset", )?; + self.update_rows(); Ok(()) }