1
0
Fork 0
mirror of https://github.com/notohh/rustlings.git synced 2025-07-29 00:20:05 -04:00

Implement resetting

This commit is contained in:
mo8it 2024-04-07 22:43:59 +02:00
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 {