Debian Codegraph @

src/regex.rs

raw symbols SCIP
1 use crate::thread::ThreadBound;
2
3 pub(crate) trait RegexEngine: Sized + ThreadBound {
4 type Error: RegexError;
5 fn is_match(&self, text: &str) -> Result<bool, Self::Error>;
6
7 fn pattern(&self) -> &str;
8 }
9
10 impl RegexEngine for fancy_regex::Regex {
11 type Error = fancy_regex::Error;
12
13 fn is_match(&self, text: &str) -> Result<bool, Self::Error> {
14 fancy_regex::Regex::is_match(self, text)
15 }
16
17 fn pattern(&self) -> &str {
18 self.as_str()
19 }
20 }
21
22 impl RegexEngine for regex::Regex {
23 type Error = regex::Error;
24
25 fn is_match(&self, text: &str) -> Result<bool, Self::Error> {
26 Ok(regex::Regex::is_match(self, text))
27 }
28
29 fn pattern(&self) -> &str {
30 self.as_str()
31 }
32 }
33
34 pub(crate) trait RegexError {
35 fn into_backtrack_error(self) -> Option<fancy_regex::Error>;
36 }
37
38 impl RegexError for fancy_regex::Error {
39 fn into_backtrack_error(self) -> Option<fancy_regex::Error> {
40 Some(self)
41 }
42 }
43
44 impl RegexError for regex::Error {
45 fn into_backtrack_error(self) -> Option<fancy_regex::Error> {
46 None
47 }
48 }