Enum regex_automata::util::prefilter::Choice

source ·
pub(crate) enum Choice {
    Memchr(Memchr),
    Memchr2(Memchr2),
    Memchr3(Memchr3),
    Memmem(Memmem),
    Teddy(Teddy),
    ByteSet(ByteSet),
    AhoCorasick(AhoCorasick),
}
Expand description

A type that encapsulates the selection of a prefilter algorithm from a sequence of needles.

The existence of this type is a little tricky, because we don’t (currently) use it for performing a search. Instead, we really only consume it by converting the underlying prefilter into a trait object, whether that be dyn PrefilterI or dyn Strategy (for the meta regex engine). In order to avoid re-copying the prefilter selection logic, we isolate it here, and then force anything downstream that wants to convert it to a trait object to do trivial case analysis on it.

One wonders whether we should use an enum instead of a trait object. At time of writing, I chose trait objects based on instinct because 1) I knew I wasn’t going to inline anything and 2) there would potentially be many different choices. However, as of time of writing, I haven’t actually compared the trait object approach to the enum approach. That probably should be litigated, but I ran out of steam.

Note that if the alloc feature is disabled, then values of this type are (and should) never be constructed. Also, in practice, for any of the prefilters to be selected, you’ll need at least one of the perf-literal-* features enabled.

Variants§

§

Memchr(Memchr)

§

Memchr2(Memchr2)

§

Memchr3(Memchr3)

§

Memmem(Memmem)

§

Teddy(Teddy)

§

ByteSet(ByteSet)

§

AhoCorasick(AhoCorasick)

Implementations§

source§

impl Choice

source

pub(crate) fn new<B: AsRef<[u8]>>( kind: MatchKind, needles: &[B], ) -> Option<Choice>

Select what is believed to be the best prefilter algorithm for the match semantics and sequence of needles given.

This selection algorithm uses the needles as given without any modification. For example, if [bar] is given, then this doesn’t try to select memchr for b. Instead, it would select memmem for bar. If callers would want memchr selected for [bar], then callers should massages the literals themselves. That is, callers are responsible for heuristics surrounding which sequence of literals is best.

What this selection algorithm does is attempt to use the fastest prefilter that works for the literals given. So if [a, b], is given, then memchr2 is selected.

Of course, which prefilter is selected is also subject to what is available. For example, if alloc isn’t enabled, then that limits which prefilters can be selected. Similarly, if perf-literal-substring isn’t enabled, then nothing from the memchr crate can be returned.

Trait Implementations§

source§

impl Clone for Choice

source§

fn clone(&self) -> Choice

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Choice

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Choice

§

impl RefUnwindSafe for Choice

§

impl Send for Choice

§

impl Sync for Choice

§

impl Unpin for Choice

§

impl UnwindSafe for Choice

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> ToOwned for T
where T: Clone,

§

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

§

type Error = Infallible

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

§

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.