Merge 2e1b42a87fc01601a5c237af64cc0763688c63a2 into 87ac600b7c050538b1622084ea7c356b8a1d02bc

This commit is contained in:
meredithdoan 2026-02-10 23:25:52 +00:00 committed by GitHub
commit 3000d47c98
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 3 deletions

View File

@ -176,10 +176,19 @@ fn main() -> Result<ExitCode> {
} }
} }
Some(Subcommands::Reset { name }) => { Some(Subcommands::Reset { name }) => {
if name == "all" {
let n_exercises = app_state.exercises().len();
for ind in 0..n_exercises {
app_state.reset_exercise_by_ind(ind)?;
}
app_state.set_current_exercise_ind(0)?;
println!("All exercises have been reset");
} else {
app_state.set_current_exercise_by_name(&name)?; app_state.set_current_exercise_by_name(&name)?;
let exercise_path = app_state.reset_current_exercise()?; let exercise_path = app_state.reset_current_exercise()?;
println!("The exercise {exercise_path} has been reset"); println!("The exercise {exercise_path} has been reset");
} }
}
Some(Subcommands::Hint { name }) => { Some(Subcommands::Hint { name }) => {
if let Some(name) = name { if let Some(name) = name {
app_state.set_current_exercise_by_name(&name)?; app_state.set_current_exercise_by_name(&name)?;

View File

@ -143,6 +143,15 @@ fn reset_without_exercise_name() {
Cmd::default().args(&["reset"]).fail(); Cmd::default().args(&["reset"]).fail();
} }
#[test]
fn reset_all() {
Cmd::default()
.current_dir("tests/test_exercises")
.args(&["reset", "all"])
.output(PartialStdout("All exercises have been reset"))
.success();
}
#[test] #[test]
fn hint() { fn hint() {
Cmd::default() Cmd::default()

View File

@ -43,6 +43,13 @@ The list allows you to…
See the footer of the list for all possible keys. See the footer of the list for all possible keys.
## Resetting Exercises
You can reset an exercise to its original state using the `reset` command:
- `rustlings reset <exercise_name>`: Reset a single exercise
- `rustlings reset all`: Reset all exercises
## Questions? ## Questions?
If you need any help while doing the exercises and the builtin hints aren't helpful, feel free to ask in the [_Q&A_ discussions](https://github.com/rust-lang/rustlings/discussions/categories/q-a?discussions_q=) if your question isn't answered there 💡 If you need any help while doing the exercises and the builtin hints aren't helpful, feel free to ask in the [_Q&A_ discussions](https://github.com/rust-lang/rustlings/discussions/categories/q-a?discussions_q=) if your question isn't answered there 💡