Skip to main content

MatchRef

Struct MatchRef 

Source
pub struct MatchRef<'c> {
    pub start: usize,
    pub end: usize,
    /* private fields */
}
Expand description

One match, borrowing the cursor that produced it.

crate::Match owns a share of the pattern’s register names, which costs the two atomics of a clone and a drop and gives every match a destructor to run. Over fifty thousand matches that is 30.2 nanoseconds each, measured against the same loop building matches that bind nothing. A caller that reads each match in turn and keeps none of them pays neither here.

Borrowed from the cursor and not from the input, so a view is invalidated by asking for the next match. MatchRef::to_match takes an owned copy where one is wanted.

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<'c> MatchRef<'c>

Source

pub fn span(&self) -> Span

The match’s own span.

Source

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

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

Source

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

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

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.

Source

pub fn to_match(&self) -> Match

This match as an owned one, which is where the share of the names and the destructor that come with it are paid for.

Auto Trait Implementations§

§

impl<'c> Freeze for MatchRef<'c>

§

impl<'c> RefUnwindSafe for MatchRef<'c>

§

impl<'c> Send for MatchRef<'c>

§

impl<'c> Sync for MatchRef<'c>

§

impl<'c> Unpin for MatchRef<'c>

§

impl<'c> UnsafeUnpin for MatchRef<'c>

§

impl<'c> UnwindSafe for MatchRef<'c>

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> 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, 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.