diff options
| author | mo8it <mo8it@proton.me> | 2024-05-25 18:19:30 +0200 |
|---|---|---|
| committer | mo8it <mo8it@proton.me> | 2024-05-25 18:19:30 +0200 |
| commit | beb7b24e8e9fe05cbcfaaf4676d52f63351fad16 (patch) | |
| tree | 782637ddff0e58c6fddcab257e0619768396b50f /src/init.rs | |
| parent | 990c68efcba8e1e2b7f2d8c5b6c16885d3920010 (diff) | |
Add solutions to bins
Diffstat (limited to 'src/init.rs')
| -rw-r--r-- | src/init.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/init.rs b/src/init.rs index 67d8a24..4063ca7 100644 --- a/src/init.rs +++ b/src/init.rs @@ -34,6 +34,20 @@ pub fn init() -> Result<()> { .init_exercises_dir(&info_file.exercises) .context("Failed to initialize the `rustlings/exercises` directory")?; + create_dir("solutions").context("Failed to create the `solutions/` directory")?; + for dir in EMBEDDED_FILES.exercise_dirs { + let mut dir_path = String::with_capacity(10 + dir.name.len()); + dir_path.push_str("solutions/"); + dir_path.push_str(dir.name); + create_dir(&dir_path) + .with_context(|| format!("Failed to create the directory {dir_path}"))?; + } + for exercise_info in &info_file.exercises { + let solution_path = exercise_info.sol_path(); + fs::write(&solution_path, INIT_SOLUTION_FILE) + .with_context(|| format!("Failed to create the file {solution_path}"))?; + } + let current_cargo_toml = include_str!("../dev-Cargo.toml"); // Skip the first line (comment). let newline_ind = current_cargo_toml @@ -72,6 +86,12 @@ pub fn init() -> Result<()> { Ok(()) } +const INIT_SOLUTION_FILE: &[u8] = b"fn main() { + // DON'T EDIT THIS SOLUTION FILE! + // It will be automatically filled after you finish the exercise. +} +"; + const GITIGNORE: &[u8] = b".rustlings-state.txt solutions Cargo.lock |
