sequent_repl/commands/
reset.rs1use std::borrow::Cow;
4use std::marker::PhantomData;
5use sequent::SimulationError;
6use revolver::command::{ApplyCommandError, ApplyOutcome, Command, Description, NamedCommandParser, ParseCommandError};
7use revolver::looper::Looper;
8use revolver::terminal::Terminal;
9use crate::Context;
10
11pub struct Reset<S, C> {
14 __phantom_data: PhantomData<(S, C)>
15}
16
17impl<S, C> Default for Reset<S, C> {
18 fn default() -> Self {
19 Self {
20 __phantom_data: PhantomData::default()
21 }
22 }
23}
24
25impl<S: Clone, C: Context<State = S>, T: Terminal> Command<T> for Reset<S, C> {
26 type Context = C;
27 type Error = SimulationError<S>;
28
29 fn apply(&mut self, looper: &mut Looper<C, SimulationError<S>, T>) -> Result<ApplyOutcome, ApplyCommandError<SimulationError<S>>> {
30 looper.context().sim().reset();
31 let (terminal, _, context) = looper.split();
32 context.print_state(terminal)?;
33 Ok(ApplyOutcome::Applied)
34 }
35}
36
37pub struct Parser<S, C> {
39 __phantom_data: PhantomData<(S, C)>
40}
41
42impl<S, C> Default for Parser<S, C> {
43 fn default() -> Self {
44 Self {
45 __phantom_data: PhantomData::default()
46 }
47 }
48}
49
50impl<S: Clone + 'static, C: Context<State = S> + 'static, T: Terminal> NamedCommandParser<T> for Parser<S, C> {
51 type Context = C;
52 type Error = SimulationError<S>;
53
54 fn parse(&self, s: &str) -> Result<Box<dyn Command<T, Context = C, Error = SimulationError<S>>>, ParseCommandError> {
55 self.parse_no_args(s, Reset::default)
56 }
57
58 fn shorthand(&self) -> Option<Cow<'static, str>> {
59 None
60 }
61
62 fn name(&self) -> Cow<'static, str> {
63 "reset".into()
64 }
65
66 fn description(&self) -> Description {
67 Description {
68 purpose: "Resets the simulation to its initial state.".into(),
69 usage: Cow::default(),
70 examples: Vec::default()
71 }
72 }
73}
74
75#[cfg(test)]
76mod tests;