litcheck_filecheck/pattern/matcher/matchers/
simple.rs1use crate::common::*;
2
3use super::{RegexMatcher, SubstringMatcher};
4
5#[derive(Debug)]
7pub enum SimpleMatcher<'a> {
8 Substring(SubstringMatcher<'a>),
10 Regex(RegexMatcher<'a>),
12}
13impl<'a> SimpleMatcher<'a> {
14 pub fn into_boxed(self) -> AnyMatcher<'a> {
15 match self {
16 Self::Substring(matcher) => Box::new(matcher),
17 Self::Regex(matcher) => Box::new(matcher),
18 }
19 }
20}
21impl<'a> MatcherMut for SimpleMatcher<'a> {
22 fn try_match_mut<'input, 'context, C>(
23 &self,
24 input: Input<'input>,
25 context: &mut C,
26 ) -> DiagResult<MatchResult<'input>>
27 where
28 C: Context<'input, 'context> + ?Sized,
29 {
30 self.try_match(input, context)
31 }
32}
33impl<'a> Matcher for SimpleMatcher<'a> {
34 fn try_match<'input, 'context, C>(
35 &self,
36 input: Input<'input>,
37 context: &C,
38 ) -> DiagResult<MatchResult<'input>>
39 where
40 C: Context<'input, 'context> + ?Sized,
41 {
42 match self {
43 Self::Substring(ref matcher) => matcher.try_match(input, context),
44 Self::Regex(ref matcher) => matcher.try_match(input, context),
45 }
46 }
47}
48impl<'a> Spanned for SimpleMatcher<'a> {
49 fn span(&self) -> SourceSpan {
50 match self {
51 Self::Substring(ref matcher) => matcher.span(),
52 Self::Regex(ref matcher) => matcher.span(),
53 }
54 }
55}