Struct regex_automata::util::search::HalfMatch
source · pub struct HalfMatch {
pattern: PatternID,
offset: usize,
}
Expand description
A representation of “half” of a match reported by a DFA.
This is called a “half” match because it only includes the end location (or start location for a reverse search) of a match. This corresponds to the information that a single DFA scan can report. Getting the other half of the match requires a second scan with a reversed DFA.
A half match also includes the pattern that matched. The pattern is
identified by an ID, which corresponds to its position (starting from 0
)
relative to other patterns used to construct the corresponding DFA. If only
a single pattern is provided to the DFA, then all matches are guaranteed to
have a pattern ID of 0
.
Fields§
§pattern: PatternID
The pattern ID.
offset: usize
The offset of the match.
For forward searches, the offset is exclusive. For reverse searches, the offset is inclusive.
Implementations§
source§impl HalfMatch
impl HalfMatch
sourcepub fn new(pattern: PatternID, offset: usize) -> HalfMatch
pub fn new(pattern: PatternID, offset: usize) -> HalfMatch
Create a new half match from a pattern ID and a byte offset.
sourcepub fn must(pattern: usize, offset: usize) -> HalfMatch
pub fn must(pattern: usize, offset: usize) -> HalfMatch
Create a new half match from a pattern ID and a byte offset.
This is like HalfMatch::new
, but accepts a usize
instead of a
PatternID
. This panics if the given usize
is not representable
as a PatternID
.