1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2025-07-03 00:46:57 +02:00

Implement resetting

This commit is contained in:
mo8it
2024-04-07 22:43:59 +02:00
parent db43efe3ec
commit 99c9ab467b
4 changed files with 53 additions and 33 deletions

View File

@ -10,7 +10,7 @@ use winnow::ascii::{space0, Caseless};
use winnow::combinator::opt;
use winnow::Parser;
use crate::embedded::EMBEDDED_FILES;
use crate::embedded::{WriteStrategy, EMBEDDED_FILES};
// The number of context lines above and below a highlighted line.
const CONTEXT: usize = 2;
@ -220,6 +220,12 @@ impl Exercise {
pub fn looks_done(&self) -> Result<bool> {
self.state().map(|state| state == State::Done)
}
pub fn reset(&self) -> Result<()> {
EMBEDDED_FILES
.write_exercise_to_disk(&self.path, WriteStrategy::Overwrite)
.with_context(|| format!("Failed to reset the exercise {self}"))
}
}
impl Display for Exercise {