mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-09-29 02:03:29 +00:00
async1: Read input from files
This commit is contained in:
committed by
Mo Bitar
parent
38a1078c23
commit
8cc9990af9
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user