use crate::{state_transducer::Input, Error};
#[derive(Debug)]
pub(crate) struct InputValidator {
input: Input,
}
impl InputValidator {
const INITIAL_INPUT: Input = Input::A1B1;
pub(crate) fn validate(&mut self, input: Input) -> Result<(), Error> {
let last_input = core::mem::replace(&mut self.input, input);
match (last_input, input) {
(Input::A0B0, Input::A1B1) => Err(Error::E00_11),
(Input::A0B1, Input::A1B0) => Err(Error::E01_10),
(Input::A1B0, Input::A0B1) => Err(Error::E10_01),
(Input::A1B1, Input::A0B0) => Err(Error::E11_00),
_ => Ok(()),
}
}
pub(crate) fn reset(&mut self) {
self.input = Self::INITIAL_INPUT;
}
}
impl Default for InputValidator {
fn default() -> Self {
Self {
input: Self::INITIAL_INPUT,
}
}
}