move input files into exercise directory

This commit is contained in:
Remo Senekowitsch
2026-08-29 22:39:33 +03:00
committed by Mo Bitar
parent b50eafb28f
commit d0109d68be
9 changed files with 49 additions and 39 deletions
+5 -9
View File
@@ -1215,6 +1215,11 @@ Add `AsRef<str>` or `AsMut<u32>` as a trait bound to the functions."""
name = "async1"
dir = "24_async"
test = false
input_files = [
"scores_class_a.txt",
"scores_class_b.txt",
"scores_class_c.txt",
]
hint = """
Asynchronous runtimes like tokio can only spawn tasks that are defined as async
functions, not regular ones. Add the "async" keyword before the "fn" keyword of
@@ -1222,12 +1227,3 @@ the functions "tim", "carl" and "nick".
An async task can wait for another one to complete by "awaiting" it. Add
".await" after the three "task_name" variables in the "block_on" call."""
[[input_files]]
name = "scores_class_a.txt"
[[input_files]]
name = "scores_class_b.txt"
[[input_files]]
name = "scores_class_c.txt"
+22 -14
View File
@@ -6,18 +6,14 @@ use serde::Deserialize;
struct ExerciseInfo<'a> {
name: &'a str,
dir: &'a str,
}
#[derive(Deserialize)]
struct InputFileInfo<'a> {
name: &'a str,
#[serde(default)]
input_files: Vec<&'a str>,
}
#[derive(Deserialize)]
struct InfoFile<'a> {
#[serde(borrow)]
exercises: Vec<ExerciseInfo<'a>>,
input_files: Vec<InputFileInfo<'a>>,
}
#[proc_macro]
@@ -47,22 +43,34 @@ pub fn include_files(_: TokenStream) -> TokenStream {
*dir_ind = dirs.len() - 1;
}
let input_files = exercises.iter().map(|exercise| {
let names = exercise.input_files.iter();
let paths = exercise
.input_files
.iter()
.map(|f| format!("../exercises/{}/{}", exercise.dir, f));
quote! {
&[#(InputFile {
name: #names,
content: include_str!(#paths),
}),*]
}
});
let readmes = dirs
.iter()
.map(|dir| format!("../exercises/{dir}/README.md"));
let input_file_names = info.input_files.iter().map(|f| f.name);
let input_file_paths = info
.input_files
.iter()
.map(|f| format!("../input_files/{}", f.name));
quote! {
EmbeddedFiles {
info_file: #info_file,
exercise_files: &[#(ExerciseFiles { exercise: include_bytes!(#exercise_files), solution: include_bytes!(#solution_files), dir_ind: #dir_inds }),*],
exercise_files: &[#(ExerciseFiles {
exercise: include_bytes!(#exercise_files),
solution: include_bytes!(#solution_files),
dir_ind: #dir_inds,
input_files: #input_files,
}),*],
exercise_dirs: &[#(ExerciseDir { name: #dirs, readme: include_bytes!(#readmes) }),*],
input_files: &[#(InputFile { name: #input_file_names, content: include_str!(#input_file_paths) }),*],
}
}
.into()