From 2dfc7cdb1a26f46c5537e10e8a182dd2125758cb Mon Sep 17 00:00:00 2001 From: mo8it Date: Mon, 13 May 2024 21:07:04 +0200 Subject: [PATCH] Document embedded --- src/embedded.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/embedded.rs b/src/embedded.rs index 39ade17..bc1a5cc 100644 --- a/src/embedded.rs +++ b/src/embedded.rs @@ -6,6 +6,7 @@ use std::{ use crate::info_file::ExerciseInfo; +// Contains all embedded files. pub static EMBEDDED_FILES: EmbeddedFiles = rustlings_macros::include_files!(); #[derive(Clone, Copy)] @@ -31,12 +32,17 @@ impl WriteStrategy { } } +// Files related to one exercise. struct ExerciseFiles { + // The content of the exercise file. exercise: &'static [u8], + // The content of the solution file. solution: &'static [u8], + // Index of the related `ExerciseDir` in `EmbeddedFiles::exercise_dirs`. dir_ind: usize, } +// A directory in the `exercises/` directory. struct ExerciseDir { name: &'static str, readme: &'static [u8], @@ -63,19 +69,20 @@ impl ExerciseDir { let mut readme_path = dir_path; readme_path.push_str("/README.md"); - WriteStrategy::Overwrite.write(&readme_path, self.readme)?; - - Ok(()) + WriteStrategy::Overwrite.write(&readme_path, self.readme) } } +// All embedded files. pub struct EmbeddedFiles { + // `info.toml` pub info_file: &'static str, exercise_files: &'static [ExerciseFiles], exercise_dirs: &'static [ExerciseDir], } impl EmbeddedFiles { + // Dump all the embedded files of the `exercises/` direcotry. pub fn init_exercises_dir(&self, exercise_infos: &[ExerciseInfo]) -> Result<()> { create_dir("exercises").context("Failed to create the directory `exercises`")?;