pub struct ExprExt(/* private fields */);
Available on crate feature compiler only.
Expand description

Configuration for extended hyperscan parameters.

These parameters cover various types of fuzzy search as well as input subsetting features. See Extended Parameters for a further reference.

This structure may be passed in when building a database with ExpressionSet::with_exts(), or used to interrogate a single expression with Expression::ext_info().

Like many other flags arguments, this struct also supports ops::BitOr and the | operator for composition:

 use hyperscan::{expression::*, flags::*, matchers::*};

 // Apply extended configuration to one version of the pattern, but not the other:
 let a: Expression = "ab".parse()?;
 let ext = ExprExt::from_min_offset(3) | ExprExt::from_max_offset(15);
 let set = ExpressionSet::from_exprs([&a, &a])
   .with_exts([Some(&ext), None])
   .with_ids([ExprId(1), ExprId(2)])
   .compile(Mode::BLOCK)?;
 let mut scratch = set.allocate_scratch()?;

 let msg: ByteSlice = "ab   ab                ab".into();

 let mut matches: Vec<ExpressionIndex> = Vec::new();
 scratch.scan_sync(&set, msg, |m| {
   matches.push(m.id);
   MatchResult::Continue
 })?;

 // The configured pattern misses out on the first and last match of "ab":
 assert_eq!(&matches, &[
   ExpressionIndex(2), ExpressionIndex(1), ExpressionIndex(2), ExpressionIndex(2),
 ]);

Implementations§

source§

impl ExprExt

source

pub fn zeroed() -> Self

Generate an empty instance with all features disabled.

source

pub fn from_min_offset(x: usize) -> Self

The minimum end offset in the data stream at which this expression should match successfully.

source

pub fn from_max_offset(x: usize) -> Self

The maximum end offset in the data stream at which this expression should match successfully.

source

pub fn from_min_length(x: usize) -> Self

The minimum match length (from start to end) required to successfully match this expression.

This is one alternative to the use of Flags::ALLOWEMPTY.

This does not require Flags::SOM_LEFTMOST:

 use hyperscan::{expression::*, flags::*, matchers::*};

 let a: Expression = "a.*b".parse()?;
 let ext = ExprExt::from_min_length(4);
 let set = ExpressionSet::from_exprs([&a])
   .with_exts([Some(&ext)])
   .compile(Mode::BLOCK)?;
 let mut scratch = set.allocate_scratch()?;

 let msg: ByteSlice = "   ab   ab   ".into();

 let mut matches: Vec<&str> = Vec::new();
 scratch.scan_sync(&set, msg, |m| {
   matches.push(unsafe { m.source.as_str() });
   MatchResult::Continue
 })?;

 // `SOM_LEFTMOST` is disabled, so we don't know the match start,
 // but the min_length property is correctly applied regardless:
 assert_eq!(&matches, &["   ab   ab"]);
source

pub fn from_edit_distance(x: usize) -> Self

Allow patterns to approximately match within this edit (Levenshtein) distance.

source

pub fn from_hamming_distance(x: usize) -> Self

Allow patterns to approximately match within this Hamming distance.

source

pub fn min_offset(&self) -> Option<c_ulonglong>

Get the min_offset value that will be provided to hyperscan, or None if not activated.

source

pub fn max_offset(&self) -> Option<c_ulonglong>

Get the max_offset value that will be provided to hyperscan, or None if not activated.

source

pub fn min_length(&self) -> Option<c_ulonglong>

Get the min_length value that will be provided to hyperscan, or None if not activated.

source

pub fn edit_distance(&self) -> Option<c_uint>

Get the edit_distance value that will be provided to hyperscan, or None if not activated.

source

pub fn hamming_distance(&self) -> Option<c_uint>

Get the hamming_distance value that will be provided to hyperscan, or None if not activated.

Trait Implementations§

source§

impl BitOr for ExprExt

§

type Output = ExprExt

The resulting type after applying the | operator.
source§

fn bitor(self, other: Self) -> Self

Performs the | operation. Read more
source§

impl BitOrAssign for ExprExt

source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
source§

impl Clone for ExprExt

source§

fn clone(&self) -> ExprExt

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 ExprExt

source§

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

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

impl Default for ExprExt

source§

fn default() -> Self

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

impl Copy for ExprExt

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