Struct ExprExt

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

Configuration for extended vectorscan 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 vectorscan::{expression::*, flags::*, matchers::*, sources::*};

 // 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 vectorscan::{expression::*, flags::*, matchers::*, sources::*};

 let a: Expression = "a.*b".parse()?;
 let ext = ExprExt::from_min_length(4);
 let set = ExpressionSet::from_exprs([&a, &a])
   // #1 has no min_length, #2 does:
   .with_exts([None, Some(&ext)])
   .with_ids([ExprId(1), ExprId(2)])
   .compile(Mode::BLOCK)?;
 let mut scratch = set.allocate_scratch()?;

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

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

 assert_eq!(&matches, &[
   // Without min_length, both matches show up:
   (1, "   ab"),
   (1, "   ab   ab"),
   // SOM_LEFTMOST is disabled, so we don't know the match start,
   // but the min_length property is correctly applied regardless:
   (2, "   ab   ab"),
 ]);
Source

pub fn from_edit_distance(x: usize) -> Self

Allow patterns to approximately match within this edit distance.

Source

pub fn from_hamming_distance(x: usize) -> Self

Allow patterns to approximately match within this Hamming distance.

Trait Implementations§

Source§

impl BitOr for ExprExt

Source§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

Source§

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

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.