Skip to main content

Match

Struct Match 

Source
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: usize

Inclusive start byte offset of the match in the input.

§end: usize

Exclusive end byte offset of the match in the input.

Implementations§

Source§

impl Match

Source

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.

Source

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.

Source

pub fn lists(&self) -> impl Iterator<Item = (&str, &[Span])>

Every register bound under a repetition, with its bindings.

Source

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.

Source

pub fn names(&self) -> &[String]

The register names, in the order Self::captures holds their spans.

Source

pub fn captures(&self) -> &[Span]

The spans this match’s registers bound, in the order Self::names holds their names.

Source

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.

Source

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.

Source

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.

Source

pub fn group_span(&self, name: &str) -> Option<Span>

The span the register called name bound.

Source

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.

Source

pub fn span(&self) -> Span

The whole match’s own span.

Source

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.

Trait Implementations§

Source§

impl Clone for Match

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Match

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for Match

Source§

impl From<Span> for Match

Source§

fn from(s: Span) -> Self

The span with no captures.

Source§

impl PartialEq for Match

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Spanned for Match

Source§

fn start(&self) -> usize

The byte offset the match begins at.
Source§

fn end(&self) -> usize

The byte offset just past it.
Source§

fn captures(&self) -> &[Span]

The register spans, in the order Self::names holds their names.
Source§

fn names(&self) -> &[String]

The register names, which belong to the pattern rather than to any one of its matches.
Source§

fn history(&self, name: &str) -> Option<&[Span]>

Every binding the register called name made, oldest first, where it is bound under a repetition; None where it is not, or where the match carries no such bindings.
Source§

impl StructuralPartialEq for Match

Auto Trait Implementations§

§

impl Freeze for Match

§

impl RefUnwindSafe for Match

§

impl Send for Match

§

impl Sync for Match

§

impl Unpin for Match

§

impl UnsafeUnpin for Match

§

impl UnwindSafe for Match

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.