Struct HalfMatch

pub struct HalfMatch { /* private fields */ }

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.

Implementations

impl HalfMatch

fn new(pattern: PatternID, offset: usize) -> HalfMatch

Create a new half match from a pattern ID and a byte offset.

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.

fn pattern(&self) -> PatternID

Returns the ID of the pattern that matched.

The ID of a pattern is derived from the position in which it was originally inserted into the corresponding DFA. The first pattern has identifier 0, and each subsequent pattern is 1, 2 and so on.

fn offset(&self) -> usize

The position of the match.

If this match was produced by a forward search, then the offset is exclusive. If this match was produced by a reverse search, then the offset is inclusive.

Trait Implementations

impl Clone for HalfMatch

fn clone(&self) -> Self

impl Copy for HalfMatch

impl Debug for HalfMatch

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl Eq for HalfMatch

impl Hash for HalfMatch

fn hash<__H: Hasher>(&self, state: &mut __H)

impl PartialEq for HalfMatch

fn eq(&self, other: &Self) -> bool

impl StructuralPartialEq for HalfMatch

Auto Trait Implementations

impl Freeze for HalfMatch

impl RefUnwindSafe for HalfMatch

impl Send for HalfMatch

impl Sync for HalfMatch

impl Unpin for HalfMatch

impl UnsafeUnpin for HalfMatch

impl UnwindSafe for HalfMatch

Blanket Implementations

impl<T> Any for HalfMatch where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for HalfMatch where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for HalfMatch where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for HalfMatch where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for HalfMatch

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for HalfMatch where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for HalfMatch where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for HalfMatch where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for HalfMatch where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>