pub struct SinglePattern { pub seq: &'static [u8], pub table: &'static [usize], } impl SinglePattern { pub fn match_against(&self, haystack: &[u8]) -> Option { let mut hay_idx = 0usize; let mut pat_idx = 0usize; while hay_idx < haystack.len() { if self.seq[pat_idx] == haystack[hay_idx] { pat_idx += 1; hay_idx += 1; }; if pat_idx == self.seq.len() { return Some(hay_idx - pat_idx); }; if hay_idx < haystack.len() && self.seq[pat_idx] != haystack[hay_idx] { if pat_idx != 0 { pat_idx = self.table[pat_idx - 1]; } else { hay_idx += 1; }; }; }; None } } pub trait ITrieNode { fn get_value(&self) -> Option; fn get_child(&self, c: u8) -> Option<&dyn ITrieNode>; } pub struct TrieLeafNode { pub value: Option, } impl ITrieNode for TrieLeafNode { fn get_value(&self) -> Option { self.value } fn get_child(&self, _: u8) -> Option<&dyn ITrieNode> { None } }