use crate::thread::ThreadBound; pub(crate) trait RegexEngine: Sized + ThreadBound { type Error: RegexError; fn is_match(&self, text: &str) -> Result; fn pattern(&self) -> &str; } impl RegexEngine for fancy_regex::Regex { type Error = fancy_regex::Error; fn is_match(&self, text: &str) -> Result { fancy_regex::Regex::is_match(self, text) } fn pattern(&self) -> &str { self.as_str() } } impl RegexEngine for regex::Regex { type Error = regex::Error; fn is_match(&self, text: &str) -> Result { Ok(regex::Regex::is_match(self, text)) } fn pattern(&self) -> &str { self.as_str() } } pub(crate) trait RegexError { fn into_backtrack_error(self) -> Option; } impl RegexError for fancy_regex::Error { fn into_backtrack_error(self) -> Option { Some(self) } } impl RegexError for regex::Error { fn into_backtrack_error(self) -> Option { None } }