mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-09-29 02:03:29 +00:00
move input files into exercise directory
This commit is contained in:
committed by
Mo Bitar
parent
b50eafb28f
commit
d0109d68be
+8
-1
@@ -17,6 +17,8 @@ struct ExerciseFiles {
|
||||
solution: &'static [u8],
|
||||
// Index of the related `ExerciseDir` in `EmbeddedFiles::exercise_dirs`.
|
||||
dir_ind: usize,
|
||||
// Files that are read by the exercise.
|
||||
input_files: &'static [InputFile],
|
||||
}
|
||||
|
||||
// Input files that may be read by exercises.
|
||||
@@ -64,7 +66,6 @@ pub struct EmbeddedFiles {
|
||||
pub info_file: &'static str,
|
||||
exercise_files: &'static [ExerciseFiles],
|
||||
pub exercise_dirs: &'static [ExerciseDir],
|
||||
pub input_files: &'static [InputFile],
|
||||
}
|
||||
|
||||
impl EmbeddedFiles {
|
||||
@@ -97,6 +98,12 @@ impl EmbeddedFiles {
|
||||
|
||||
fs::write(&exercise_path, exercise_files.exercise)
|
||||
.with_context(|| format!("Failed to write the exercise file {exercise_path}"))?;
|
||||
|
||||
for InputFile { name, content } in exercise_files.input_files {
|
||||
let path = format!("{prefix}/{dir_name}/{name}", dir_name = dir.name);
|
||||
fs::write(&path, content)
|
||||
.with_context(|| format!("Failed to write the input file {path}"))?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -144,15 +144,6 @@ pub fn init() -> Result<()> {
|
||||
.with_context(|| format!("Failed to create the file {solution_path}"))?;
|
||||
}
|
||||
|
||||
// init input files
|
||||
create_dir("input_files").context("Failed to create the directory `input_files`")?;
|
||||
for input_file in EMBEDDED_FILES.input_files {
|
||||
fs::write(
|
||||
format!("input_files/{}", input_file.name),
|
||||
input_file.content,
|
||||
)?;
|
||||
}
|
||||
|
||||
let current_cargo_toml = include_str!("../dev-Cargo.toml");
|
||||
// Skip the first line (comment).
|
||||
let newline_ind = current_cargo_toml
|
||||
|
||||
Reference in New Issue
Block a user