mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-12-28 06:49:19 +00:00
WIP: add one aditional module file for exercise support
This commit is contained in:
parent
42b924aeab
commit
0219ef7cc9
@ -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(),
|
||||
|
||||
@ -11,6 +11,9 @@ pub struct ExerciseInfo {
|
||||
pub name: String,
|
||||
/// Exercise's directory name inside the `exercises/` directory.
|
||||
pub dir: Option<String>,
|
||||
/// Extra one Aditional Module file
|
||||
#[serde(default)]
|
||||
pub module_file: Option<String>,
|
||||
/// 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<String> {
|
||||
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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user