Struct Builder
pub struct Builder { /* private fields */ }
A builder for a PikeVM.
This builder permits configuring options for the syntax of a pattern,
the NFA construction and the PikeVM construction. This builder is
different from a general purpose regex builder in that it permits fine
grain configuration of the construction process. The trade off for this is
complexity, and the possibility of setting a configuration that might not
make sense. For example, there are two different UTF-8 modes:
util::syntax::Config::utf8controls whether the pattern itself can contain sub-expressions that match invalid UTF-8.thompson::Config::utf8controls whether empty matches that split a Unicode codepoint are reported or not.
Generally speaking, callers will want to either enable all of these or disable all of these.
Example
This example shows how to disable UTF-8 mode in the syntax and the regex itself. This is generally what you want for matching on arbitrary bytes.
use ;
let re = builder
.syntax
.thompson
.build?;
let mut cache = re.create_cache;
let haystack = b"\xFEfoo\xFFarzz\xE2\x98\xFF\n";
let expected = Some;
let got = re.find_iter.next;
assert_eq!;
// Notice that `(?-u:[^b])` matches invalid UTF-8,
// but the subsequent `.*` does not! Disabling UTF-8
// on the syntax permits this.
//
// N.B. This example does not show the impact of
// disabling UTF-8 mode on a PikeVM Config, since that
// only impacts regexes that can produce matches of
// length 0.
assert_eq!;
# Ok::
Implementations
impl Builder
fn new() -> BuilderCreate a new PikeVM builder with its default configuration.
fn build(&self, pattern: &str) -> Result<PikeVM, BuildError>Build a
PikeVMfrom the given pattern.If there was a problem parsing or compiling the pattern, then an error is returned.
fn build_many<P: AsRef<str>>(&self, patterns: &[P]) -> Result<PikeVM, BuildError>Build a
PikeVMfrom the given patterns.fn build_from_nfa(&self, nfa: NFA) -> Result<PikeVM, BuildError>Build a
PikeVMdirectly from its NFA.Note that when using this method, any configuration that applies to the construction of the NFA itself will of course be ignored, since the NFA given here is already built.
fn configure(&mut self, config: Config) -> &mut BuilderApply the given
PikeVMconfiguration options to this builder.fn syntax(&mut self, config: Config) -> &mut BuilderSet the syntax configuration for this builder using
syntax::Config.This permits setting things like case insensitivity, Unicode and multi line mode.
These settings only apply when constructing a PikeVM directly from a pattern.
fn thompson(&mut self, config: Config) -> &mut BuilderSet the Thompson NFA configuration for this builder using
nfa::thompson::Config.This permits setting things like if additional time should be spent shrinking the size of the NFA.
These settings only apply when constructing a PikeVM directly from a pattern.
Trait Implementations
impl Clone for Builder
fn clone(&self) -> Self
impl Debug for Builder
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Auto Trait Implementations
impl !Freeze for Builder
impl !RefUnwindSafe for Builder
impl !Sync for Builder
impl Send for Builder
impl Unpin for Builder
impl UnsafeUnpin for Builder
impl UnwindSafe for Builder
Blanket Implementations
impl<T> Any for Builder
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Builder
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Builder
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Builder
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Builder
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Builder
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for Builder
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Builder
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Builder
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>