pub struct Match {
pub start: usize,
pub end: usize,
/* private fields */
}Expand description
A reported match: a half-open byte span plus the registers bound when the match completed.
Fields§
§start: usizeInclusive start byte offset of the match in the input.
end: usizeExclusive end byte offset of the match in the input.
Implementations§
Source§impl Match
impl Match
Sourcepub fn plain(start: usize, end: usize) -> Self
pub fn plain(start: usize, end: usize) -> Self
A match with no registers bound.
Inlined because a cursor builds one a match: it is five field writes, and a call to it across the module boundary costs more than the writes.
Sourcepub fn list(&self, name: &str) -> Option<&[Span]>
pub fn list(&self, name: &str) -> Option<&[Span]>
Every binding the register called name made in this match, oldest
first, where the register is bound under a repetition; None for a
register that is not, whose one binding Self::group_span holds.
Sourcepub fn lists(&self) -> impl Iterator<Item = (&str, &[Span])>
pub fn lists(&self) -> impl Iterator<Item = (&str, &[Span])>
Every register bound under a repetition, with its bindings.
Sourcepub fn bound(
start: usize,
end: usize,
captures: Regs,
names: Arc<[String]>,
) -> Self
pub fn bound( start: usize, end: usize, captures: Regs, names: Arc<[String]>, ) -> Self
A match with captures, named by names in the same order.
An empty names is held as none, so a match of a pattern naming no
register is the same match however it was built.
Sourcepub fn names(&self) -> &[String]
pub fn names(&self) -> &[String]
The register names, in the order Self::captures holds their spans.
Sourcepub fn captures(&self) -> &[Span]
pub fn captures(&self) -> &[Span]
The spans this match’s registers bound, in the order Self::names
holds their names.
Sourcepub fn captures_mut(&mut self) -> &mut [Span]
pub fn captures_mut(&mut self) -> &mut [Span]
The register spans to write through, for a caller rebasing this match onto another region of the input.
Sourcepub fn shifted(self, by: usize) -> Match
pub fn shifted(self, by: usize) -> Match
This match found over a window of a longer input, as a match of that
input: its span, its registers and every binding made under a
repetition moved by by, where the window begins in it.
§Panics
A register moved past the widest offset a span holds.
Sourcepub fn group<'h>(&self, name: &str, input: &'h [u8]) -> Option<&'h [u8]>
pub fn group<'h>(&self, name: &str, input: &'h [u8]) -> Option<&'h [u8]>
The bytes the register called name bound, or None where the
pattern has no such register.
A register the pattern has but this match did not bind returns an empty slice, which is the same answer as binding nothing and is not the same as the pattern never naming it.
Sourcepub fn group_span(&self, name: &str) -> Option<Span>
pub fn group_span(&self, name: &str) -> Option<Span>
The span the register called name bound.
Sourcepub fn group_at<'h>(&self, i: usize, input: &'h [u8]) -> Option<&'h [u8]>
pub fn group_at<'h>(&self, i: usize, input: &'h [u8]) -> Option<&'h [u8]>
The bytes of the ith register, in the order this match carries them.
Positional access exists because a caller that knows the pattern knows the positions; a caller that does not should ask by name, which is the handle the pattern actually gave the register.
Sourcepub fn extract<'h, const N: usize>(
&self,
input: &'h [u8],
) -> (&'h [u8], [&'h [u8]; N])
pub fn extract<'h, const N: usize>( &self, input: &'h [u8], ) -> (&'h [u8], [&'h [u8]; N])
The whole match and every register it bound, as a fixed-size array.
The counterpart of the regex crate’s Captures::extract, which exists
to destructure a match in one binding rather than unwrapping a group at
a time. Registers arrive in the order Self::captures holds them,
sorted by name: every trex binding is named and there are no numbered
groups, so there is no group number to order them by.
crate::static_captures_len is what says N is right for a pattern
before any input is seen.
§Panics
When N is not the number of registers this match bound. That is the
same contract regex’s has, and the reason both are checked rather than
truncated: a silently short array would bind the wrong register to the
wrong name.