From 0219ef7cc99168e02c5fb142bcc1657dd8c354d1 Mon Sep 17 00:00:00 2001 From: eveeifyeve <88671402+Eveeifyeve@users.noreply.github.com> Date: Sun, 5 Oct 2025 23:49:20 +1100 Subject: [PATCH] WIP: add one aditional module file for exercise support --- src/cargo_toml.rs | 2 ++ src/info_file.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/cargo_toml.rs b/src/cargo_toml.rs index ce0dfd0c..d624f867 100644 --- a/src/cargo_toml.rs +++ b/src/cargo_toml.rs @@ -108,6 +108,7 @@ mod tests { ExerciseInfo { name: String::from("1"), dir: None, + module_file: None, test: true, strict_clippy: true, hint: String::new(), @@ -116,6 +117,7 @@ mod tests { ExerciseInfo { name: String::from("2"), dir: Some(String::from("d")), + module_file: None, test: false, strict_clippy: false, hint: String::new(), diff --git a/src/info_file.rs b/src/info_file.rs index 04e5d644..b0603dd9 100644 --- a/src/info_file.rs +++ b/src/info_file.rs @@ -11,6 +11,9 @@ pub struct ExerciseInfo { pub name: String, /// Exercise's directory name inside the `exercises/` directory. pub dir: Option, + /// Extra one Aditional Module file + #[serde(default)] + pub module_file: Option, /// Run `cargo test` on the exercise. #[serde(default = "default_true")] pub test: bool, @@ -52,6 +55,33 @@ impl ExerciseInfo { path } + + pub fn module_file_path(&self) -> Option { + if let Some(module_path) = &self.module_file { + let mut path = if let Some(dir) = &self.dir { + // 14 = 10 + 1 + 3 + // exercises/ + / + .rs + let mut path = String::with_capacity(14 + dir.len() + module_path.len()); + path.push_str("exercises/"); + path.push_str(dir); + path.push('/'); + path + } else { + // 13 = 10 + 3 + // exercises/ + .rs + let mut path = String::with_capacity(13 + module_path.len()); + path.push_str("exercises/"); + path + }; + + path.push_str(&module_path); + path.push_str(".rs"); + + Some(path) + } else { + None + } + } } impl RunnableExercise for ExerciseInfo {