1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
pub trait Automaton { type State: Copy; fn start(&self) -> Self::State; fn is_match(&self, state: Self::State) -> bool; fn accept(&self, state: Self::State, byte: u8) -> Option<Self::State>; } pub struct AlwaysMatch; impl Automaton for AlwaysMatch { type State = (); fn start(&self) -> () { () } fn is_match(&self, _: ()) -> bool { true } fn accept(&self, _: (), _: u8) -> Option<()> { Some(()) } }