1use std::fmt::{self, Debug};
2use std::hash::Hash;
3use std::iter::FusedIterator;
4use std::marker::PhantomData;
5
6use crate::expr::IndexedCaptures;
7use crate::haystack::{HaystackItem, HaystackOf};
8use crate::matcher::Matcher;
9
10#[derive(#[automatically_derived]
impl<'a, I: ::core::fmt::Debug, H: ::core::fmt::Debug, A: ::core::fmt::Debug,
const N : usize> ::core::fmt::Debug for AllCapturesGroup<'a, I, H, A, N>
where I: HaystackItem, H: HaystackOf<'a, I>, A: Matcher<I>,
A::AllCaptures<'a, H>: ::core::fmt::Debug {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"AllCapturesGroup", "captures", &self.captures, "start",
&&self.start)
}
}Debug, #[automatically_derived]
impl<'a, I: ::core::clone::Clone, H: ::core::clone::Clone,
A: ::core::clone::Clone, const N : usize> ::core::clone::Clone for
AllCapturesGroup<'a, I, H, A, N> where I: HaystackItem,
H: HaystackOf<'a, I>, A: Matcher<I>,
A::AllCaptures<'a, H>: ::core::clone::Clone {
#[inline]
fn clone(&self) -> AllCapturesGroup<'a, I, H, A, N> {
AllCapturesGroup {
captures: ::core::clone::Clone::clone(&self.captures),
start: ::core::clone::Clone::clone(&self.start),
}
}
}Clone, #[automatically_derived]
impl<'a, I: ::core::hash::Hash, H: ::core::hash::Hash, A: ::core::hash::Hash,
const N : usize> ::core::hash::Hash for AllCapturesGroup<'a, I, H, A, N>
where I: HaystackItem, H: HaystackOf<'a, I>, A: Matcher<I>,
A::AllCaptures<'a, H>: ::core::hash::Hash {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.captures, state);
::core::hash::Hash::hash(&self.start, state)
}
}Hash)]
11pub struct AllCapturesGroup<'a, I, H, A, const N: usize>
12where
13 I: HaystackItem,
14 H: HaystackOf<'a, I>,
15 A: Matcher<I>,
16{
17 captures: A::AllCaptures<'a, H>,
18 start: usize,
19}
20
21impl<'a, I, H, A, const N: usize> Iterator for AllCapturesGroup<'a, I, H, A, N>
22where
23 I: HaystackItem,
24 H: HaystackOf<'a, I>,
25 A: Matcher<I>,
26{
27 type Item = (usize, IndexedCaptures);
28
29 fn next(&mut self) -> Option<Self::Item> {
30 let (state_fork, mut caps_fork) = self.captures.next()?;
31 caps_fork.push(N, self.start..state_fork);
32 Some((state_fork, caps_fork))
33 }
34}
35
36impl<'a, I, H, A, const N: usize> FusedIterator for AllCapturesGroup<'a, I, H, A, N>
37where
38 I: HaystackItem,
39 H: HaystackOf<'a, I>,
40 A: Matcher<I>,
41{}
42
43#[derive(#[automatically_derived]
impl<I: ::core::default::Default + HaystackItem, A: ::core::default::Default +
Matcher<I>, const N : usize> ::core::default::Default for
CaptureGroup<I, A, N> {
#[inline]
fn default() -> CaptureGroup<I, A, N> {
CaptureGroup(::core::default::Default::default(),
::core::default::Default::default())
}
}Default, #[automatically_derived]
impl<I: ::core::clone::Clone + HaystackItem, A: ::core::clone::Clone +
Matcher<I>, const N : usize> ::core::clone::Clone for
CaptureGroup<I, A, N> {
#[inline]
fn clone(&self) -> CaptureGroup<I, A, N> {
CaptureGroup(::core::clone::Clone::clone(&self.0),
::core::clone::Clone::clone(&self.1))
}
}Clone, #[automatically_derived]
impl<I: ::core::marker::Copy + HaystackItem, A: ::core::marker::Copy +
Matcher<I>, const N : usize> ::core::marker::Copy for
CaptureGroup<I, A, N> {
}Copy)]
44pub struct CaptureGroup<I: HaystackItem, A: Matcher<I>, const N: usize>(
45 pub PhantomData<I>,
46 pub PhantomData<A>,
47);
48
49impl<I: HaystackItem, A: Matcher<I>, const N: usize> Matcher<I> for CaptureGroup<I, A, N> {
50 type AllMatches<'a, H: HaystackOf<'a, I>> = A::AllMatches<'a, H>;
51 type AllCaptures<'a, H: HaystackOf<'a, I>> = AllCapturesGroup<'a, I, H, A, N>;
52
53 fn matches<'a, H: HaystackOf<'a, I>>(hay: &mut H) -> bool {
54 A::matches(hay)
55 }
56
57 fn all_matches<'a, H: HaystackOf<'a, I>>(hay: &mut H) -> Self::AllMatches<'a, H> {
58 A::all_matches(hay)
59 }
60
61 fn captures<'a, H: HaystackOf<'a, I>>(hay: &mut H, caps: &mut IndexedCaptures) -> bool {
62 let start = hay.index();
63 if A::captures(hay, caps) {
64 caps.push(N, start..hay.index());
65 true
66 } else {
67 false
68 }
69 }
70
71 fn all_captures<'a, H: HaystackOf<'a, I>>(
72 hay: &mut H,
73 caps: &mut IndexedCaptures,
74 ) -> Self::AllCaptures<'a, H> {
75 AllCapturesGroup {
76 start: hay.index(),
77 captures: A::all_captures(hay, caps),
78 }
79 }
80}
81
82impl<I: HaystackItem, A: Matcher<I>, const N: usize> Debug for CaptureGroup<I, A, N> {
83 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
84 f.write_fmt(format_args!("({0:?})", A::default()))write!(f, "({:?})", A::default())
85 }
86}