Skip to main content

Matcher

Struct Matcher 

Source
pub struct Matcher { /* private fields */ }
Expand description

The scratch a match needs, kept across calls.

ARGREP runs a predicate per visited element, so the three vectors are allocated once for the command rather than once per element. A Matcher can be used with any Regex; it grows to the largest one it has seen.

Implementations§

Source§

impl Matcher

Source

pub fn new() -> Matcher

A matcher with nothing allocated yet.

Source

pub fn reserve(&mut self, re: &Regex)

Grows the scratch to what re will need, so that matching never does.

A state is added at most once per step, so none of the four vectors can go past the program size. Doing the growth here means the caller can put every allocation ARGREP makes in the part of the command that reads the arguments, and the walk over the elements allocates nothing at all.

Source

pub fn is_match(&mut self, re: &Regex, hay: &[u8]) -> bool

Whether re matches anywhere in hay.

Unanchored, which is what regexec without an anchor does and what ARGREP RE means: the pattern has to match some run of bytes, not the whole element.

The walk is a Thompson simulation. Every state that could be live at a position is live at once, so a byte is looked at exactly once and the cost is the subject length times the program size in the worst case, with no backtracking and therefore no pattern that makes it exponential.

Trait Implementations§

Source§

impl Debug for Matcher

Source§

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

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

impl Default for Matcher

Source§

fn default() -> Matcher

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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, 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, <T as TryFrom<U>>::Error>

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.