async1: Read input from files

This commit is contained in:
Remo Senekowitsch
2026-08-29 22:39:33 +03:00
committed by Mo Bitar
parent 38a1078c23
commit 8cc9990af9
10 changed files with 107 additions and 66 deletions
+7
View File
@@ -19,6 +19,12 @@ struct ExerciseFiles {
dir_ind: usize,
}
// Input files that may be read by exercises.
pub struct InputFile {
pub name: &'static str,
pub content: &'static str,
}
fn create_dir_if_not_exists(path: &str) -> Result<()> {
if let Err(e) = create_dir(path)
&& e.kind() != io::ErrorKind::AlreadyExists
@@ -58,6 +64,7 @@ pub struct EmbeddedFiles {
pub info_file: &'static str,
exercise_files: &'static [ExerciseFiles],
pub exercise_dirs: &'static [ExerciseDir],
pub input_files: &'static [InputFile],
}
impl EmbeddedFiles {
+9
View File
@@ -144,6 +144,15 @@ 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