ct_regex_internal/expr/
captures.rs1use std::fmt::Debug;
2use std::ops::Range;
3
4use standard_lib::collections::cons::ConsBranch;
5
6use crate::haystack::HaystackSlice;
7
8#[derive(#[automatically_derived]
impl ::core::fmt::Debug for IndexedCaptures {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"IndexedCaptures", &&self.0)
}
}Debug, #[automatically_derived]
impl ::core::default::Default for IndexedCaptures {
#[inline]
fn default() -> IndexedCaptures {
IndexedCaptures(::core::default::Default::default())
}
}Default, #[automatically_derived]
impl ::core::clone::Clone for IndexedCaptures {
#[inline]
fn clone(&self) -> IndexedCaptures {
IndexedCaptures(::core::clone::Clone::clone(&self.0))
}
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for IndexedCaptures {
#[inline]
fn eq(&self, other: &IndexedCaptures) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for IndexedCaptures {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<ConsBranch<IndexedCapture>>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for IndexedCaptures {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}Hash)]
9pub struct IndexedCaptures(pub ConsBranch<IndexedCapture>);
10
11#[derive(#[automatically_derived]
impl ::core::fmt::Debug for IndexedCapture {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"IndexedCapture", "index", &self.index, "cap", &&self.cap)
}
}Debug, #[automatically_derived]
impl ::core::clone::Clone for IndexedCapture {
#[inline]
fn clone(&self) -> IndexedCapture {
IndexedCapture {
index: ::core::clone::Clone::clone(&self.index),
cap: ::core::clone::Clone::clone(&self.cap),
}
}
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for IndexedCapture {
#[inline]
fn eq(&self, other: &IndexedCapture) -> bool {
self.index == other.index && self.cap == other.cap
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for IndexedCapture {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<usize>;
let _: ::core::cmp::AssertParamIsEq<Range<usize>>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for IndexedCapture {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.index, state);
::core::hash::Hash::hash(&self.cap, state)
}
}Hash)]
12pub struct IndexedCapture {
13 pub index: usize,
14 pub cap: Range<usize>,
15}
16
17impl IndexedCaptures {
18 pub fn push(&mut self, index: usize, cap: Range<usize>) {
19 self.0.push(IndexedCapture { index, cap });
20 }
21
22 pub fn into_array<const N: usize>(self) -> [Option<Range<usize>>; N] {
25 let mut res = [const { None }; N];
26
27 for item in self.0.into_iter_owned() {
28 match res.get(item.index) {
29 None => {
::core::panicking::panic_fmt(format_args!("capture index exceeds maximum group number"));
}panic!("capture index exceeds maximum group number"),
30 Some(None) => res[item.index] = Some(item.cap.clone()),
31 Some(_) => (),
34 }
35 }
36
37 res
38 }
39}
40
41pub trait CaptureFromRanges<'a, S: HaystackSlice<'a>, const N: usize>: Sized + Debug {
42 fn from_ranges(ranges: [Option<Range<usize>>; N], slice: S) -> Option<Self>;
43 fn whole_match_range(&self) -> Range<usize>;
44}