pub trait Automaton {
type State;
fn start(&self) -> Self::State;
fn is_match(&self, state: &Self::State) -> bool;
fn can_match(&self, state: &Self::State) -> bool;
fn accept(&self, state: &Self::State, byte: u8) -> Self::State;
}
impl<'a, T: Automaton> Automaton for &'a T {
type State = T::State;
fn start(&self) -> Self::State {
(*self).start()
}
fn is_match(&self, state: &Self::State) -> bool {
(*self).is_match(state)
}
fn can_match(&self, state: &Self::State) -> bool {
(*self).can_match(state)
}
fn accept(&self, state: &Self::State, byte: u8) -> Self::State {
(*self).accept(state, byte)
}
}
pub struct AlwaysMatch;
impl Automaton for AlwaysMatch {
type State = ();
fn start(&self) -> () { () }
fn is_match(&self, _: &()) -> bool { true }
fn can_match(&self, _: &()) -> bool { true }
fn accept(&self, _: &(), _: u8) -> () { () }
}