1use std::ops::Range;
2
3use super::Regex;
4use crate::expr::{FindAllCaptures, RangeOfAllMatches, SliceAllMatches};
5use crate::haystack::{HaystackItem, HaystackIter, HaystackOf, IntoHaystack, OwnedHaystackable};
6
7pub trait AnonRegex<I: HaystackItem, const N: usize>: Regex<I, N> {
14 fn is_match<'a, H: HaystackOf<'a, I>>(&self, hay: impl IntoHaystack<'a, H>) -> bool {
16 <Self as Regex<I, N>>::is_match(hay)
17 }
18
19 fn contains_match<'a, H: HaystackOf<'a, I>>(&self, hay: impl IntoHaystack<'a, H>) -> bool {
21 <Self as Regex<I, N>>::contains_match(hay)
22 }
23
24 fn count_matches<'a, H: HaystackOf<'a, I>>(
26 &self,
27 hay: impl IntoHaystack<'a, H>,
28 overlapping: bool,
29 ) -> usize {
30 <Self as Regex<I, N>>::count_matches(hay, overlapping)
31 }
32
33 fn range_of_match<'a, H: HaystackOf<'a, I>>(
35 &self,
36 hay: impl IntoHaystack<'a, H>,
37 ) -> Option<Range<usize>> {
38 <Self as Regex<I, N>>::range_of_match(hay)
39 }
40
41 fn range_of_all_matches<'a, H: HaystackOf<'a, I>>(
43 &self,
44 hay: impl IntoHaystack<'a, H>,
45 overlapping: bool,
46 ) -> RangeOfAllMatches<'a, I, H, Self::Pattern> {
47 <Self as Regex<I, N>>::range_of_all_matches(hay, overlapping)
48 }
49
50 fn slice_match<'a, H: HaystackOf<'a, I>>(
52 &self,
53 hay: impl IntoHaystack<'a, H>,
54 ) -> Option<H::Slice> {
55 <Self as Regex<I, N>>::slice_match(hay)
56 }
57
58 fn slice_all_matches<'a, H: HaystackOf<'a, I>>(
60 &self,
61 hay: impl IntoHaystack<'a, H>,
62 overlapping: bool,
63 ) -> SliceAllMatches<'a, I, H, Self::Pattern> {
64 <Self as Regex<I, N>>::slice_all_matches(hay, overlapping)
65 }
66
67 fn do_capture<'a, H: HaystackOf<'a, I>>(
69 &self,
70 hay: impl IntoHaystack<'a, H>,
71 ) -> Option<Self::Capture<'a, H::Slice>> {
72 <Self as Regex<I, N>>::do_capture(hay)
73 }
74
75 fn find_capture<'a, H: HaystackOf<'a, I>>(
77 &self,
78 hay: impl IntoHaystack<'a, H>,
79 ) -> Option<Self::Capture<'a, H::Slice>> {
80 <Self as Regex<I, N>>::find_capture(hay)
81 }
82
83 fn find_all_captures<'a, H: HaystackOf<'a, I>>(
85 &self,
86 hay: impl IntoHaystack<'a, H>,
87 overlapping: bool,
88 ) -> FindAllCaptures<'a, Self, I, H, N> {
89 <Self as Regex<I, N>>::find_all_captures(hay, overlapping)
90 }
91
92 fn replace<'a, M: OwnedHaystackable<I>>(
94 &self,
95 hay_mut: &mut M,
96 with: <M::Hay<'a> as HaystackIter<'a>>::Slice
97 ) -> bool {
98 <Self as Regex<I, N>>::replace(hay_mut, with)
99 }
100
101 fn replace_all<'a, M: OwnedHaystackable<I>>(
103 &self,
104 hay_mut: &mut M,
105 with: <M::Hay<'a> as HaystackIter<'a>>::Slice
106 ) -> usize {
107 <Self as Regex<I, N>>::replace_all(hay_mut, with)
108 }
109
110 fn replace_all_using<M: OwnedHaystackable<I>>(
112 &self,
113 hay_mut: &mut M,
114 using: impl FnMut() -> M,
115 ) -> usize {
116 <Self as Regex<I, N>>::replace_all_using(hay_mut, using)
117 }
118
119 fn replace_captured<M, F>(&self, hay_mut: &mut M, replacer: F) -> bool
121 where
122 M: OwnedHaystackable<I>,
123 F: for<'a> FnOnce(Self::Capture<'a, <M::Hay<'a> as HaystackIter<'a>>::Slice>) -> M,
124 {
125 <Self as Regex<I, N>>::replace_captured::<M, F>(hay_mut, replacer)
126 }
127
128 fn replace_all_captured<M, F>(&self, hay_mut: &mut M, replacer: F) -> usize
130 where
131 M: OwnedHaystackable<I>,
132 F: for<'a> FnMut(Self::Capture<'a, <M::Hay<'a> as HaystackIter<'a>>::Slice>) -> M,
133 {
134 <Self as Regex<I, N>>::replace_all_captured::<M, F>(hay_mut, replacer)
135 }
136}