ct_regex_internal/expr/
anon.rs

1use crate::haystack::{HaystackItem, HaystackOf, IntoHaystack};
2use super::Regex;
3
4/// A trait that is automatically implemented for 'anonymous' regular expression types. There is
5/// only one difference between this and [`Regex`]: all functions take self as the first parameter,
6/// removing the need to name the type itself.
7///
8/// An `AnonRegex` can be created by invoking `regex!()` without a type identifier or visibility.
9/// The result is an instance of an unnamable type implementing `AnonRegex`.
10pub trait AnonRegex<I: HaystackItem, const N: usize>: Regex<I, N> {
11    /// See [`Regex::is_match`].
12    fn is_match<'a, H: HaystackOf<'a, I>>(&self, hay: impl IntoHaystack<'a, H>) -> bool {
13        <Self as Regex<I, N>>::is_match(hay)
14    }
15
16    /// See [`Regex::contains_match`].
17    fn contains_match<'a, H: HaystackOf<'a, I>>(&self, hay: impl IntoHaystack<'a, H>) -> bool {
18        <Self as Regex<I, N>>::contains_match(hay)
19    }
20
21    /// See [`Regex::slice_matching`].
22    fn slice_matching<'a, H: HaystackOf<'a, I>>(
23        &self,
24        hay: impl IntoHaystack<'a, H>
25    ) -> Option<H::Slice> {
26        <Self as Regex<I, N>>::slice_matching(hay)
27    }
28
29    /// See [`Regex::slice_all_matching`].
30    fn slice_all_matching<'a, H: HaystackOf<'a, I>>(
31        &self,
32        hay: impl IntoHaystack<'a, H>,
33        overlapping: bool
34    ) -> Vec<H::Slice> {
35        <Self as Regex<I, N>>::slice_all_matching(hay, overlapping)
36    }
37
38    /// See [`Regex::do_capture`].
39    fn do_capture<'a, H: HaystackOf<'a, I>>(
40        &self,
41        hay: impl IntoHaystack<'a, H>
42    ) -> Option<Self::Capture<'a, H>> {
43        <Self as Regex<I, N>>::do_capture(hay)
44    }
45
46    /// See [`Regex::find_capture`].
47    fn find_capture<'a, H: HaystackOf<'a, I>>(
48        &self,
49        hay: impl IntoHaystack<'a, H>
50    ) -> Option<Self::Capture<'a, H>> {
51        <Self as Regex<I, N>>::find_capture(hay)
52    }
53
54    /// See [`Regex::find_all_captures`].
55    fn find_all_captures<'a, H: HaystackOf<'a, I>>(
56        &self,
57        hay: impl IntoHaystack<'a, H>,
58        overlapping: bool
59    ) -> Vec<Self::Capture<'a, H>> {
60        <Self as Regex<I, N>>::find_all_captures(hay, overlapping)
61    }
62}