Struct regex_test::Captures
source · pub struct Captures { /* private fields */ }
Expand description
Captures represents a single group of captured matches from a regex search.
There is always at least 1 group, and the first group is always present and corresponds to the overall match.
Implementations§
source§impl Captures
impl Captures
sourcepub fn new<I: IntoIterator<Item = Option<Span>>>(
id: usize,
it: I
) -> Result<Captures>
pub fn new<I: IntoIterator<Item = Option<Span>>>( id: usize, it: I ) -> Result<Captures>
Create a new set of captures for a single match of a regex.
If available, iterator should provide items for every capturing group in the regex, including the 0th capturing group corresponding to the entire match. At minimum, the 0th capturing group should be provided.
If a capturing group did not participate in the match, then a None
value should be used. (The 0th capturing group should never be None
.)
If the iterator yields no elements or the first group is None
, then
this returns an error.
The id
should be the ID of the pattern that matched. This is always
0
for single-pattern regexes. Otherwise, the ID of a pattern starts
at 0
and is incremented by 1 for each subsequent pattern.
Note that there are possibly more convenient and infallible From
impls for converting a Match
or a Span
into a Captures
.
sourcepub fn id(&self) -> usize
pub fn id(&self) -> usize
Returns the ID of the pattern that matched.
For any single pattern regexes, this should always be zero.
sourcepub fn groups(&self) -> &[Option<Span>]
pub fn groups(&self) -> &[Option<Span>]
Returns a slice of the underlying spans, each group corresponding to
the (possibly) matched span. The first group in the slice returned
is guaranteed to correspond to the overall match span and is thus
non-None
. All other groups may be None
. Similarly, the slice is
guaranteed to have length at least 1.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of groups (including the first) in these captures.
The length returned is guaranteed to be greater than zero.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Captures
impl<'de> Deserialize<'de> for Captures
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl From<Match> for Captures
impl From<Match> for Captures
Converts a plain Match
to a Captures
value, where the match corresponds
to the first and only group in Captures
.
source§impl From<Span> for Captures
impl From<Span> for Captures
Converts a plain Span
to a Captures
value, where the span corresponds to
the first and only group in Captures
. Since a Span
does not contain a
pattern ID, the pattern ID used in this conversion is always 0
.
source§impl PartialEq<Captures> for Captures
impl PartialEq<Captures> for Captures
impl Eq for Captures
impl StructuralEq for Captures
impl StructuralPartialEq for Captures
Auto Trait Implementations§
impl RefUnwindSafe for Captures
impl Send for Captures
impl Sync for Captures
impl Unpin for Captures
impl UnwindSafe for Captures
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.