Struct hyperscan::expression::Expression
source · pub struct Expression(/* private fields */);compiler only.Expand description
Hyperscan regex pattern string.
Hyperscan itself supports a subset of PCRE syntax in the pattern string; see Pattern Support for reference. The use of unsupported constructs will result in compilation errors.
Note that as the underlying hyperscan library interprets pattern strings as
essentially null-terminated CStr pointers, null bytes
are not supported within Expression strings. Use a Literal or
LiteralSet database if you need to match against patterns with null
bytes.
Instances can be created equivalently with Self::new() or
str::parse() via the str::FromStr impl:
use hyperscan::expression::Expression;
let e1: Expression = "asdf+".parse()?;
let e2 = Expression::new("asdf+")?;
assert_eq!(e1, e2);Implementations§
source§impl Expression
impl Expression
sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Reference the underlying bytes, without the trailing null terminator.
let e = hyperscan::expression::Expression::new("asdf")?;
assert_eq!(e.as_bytes(), b"asdf");sourcepub fn new(x: impl Into<Vec<u8>>) -> Result<Self, HyperscanCompileError>
pub fn new(x: impl Into<Vec<u8>>) -> Result<Self, HyperscanCompileError>
Produce a NULL-terminated C-style wrapper for the given pattern string.
This will fail if the string contains any internal NULL bytes, as those
are not supported by the hyperscan regex compiler:
use hyperscan::{expression::*, error::*};
let pat = "as\0df";
let e = match Expression::new(pat) {
Err(HyperscanCompileError::NullByte(e)) => e,
_ => unreachable!(),
};
assert_eq!(e.nul_position(), 2);sourcepub fn info(&self, flags: Flags) -> Result<ExprInfo, HyperscanCompileError>
pub fn info(&self, flags: Flags) -> Result<ExprInfo, HyperscanCompileError>
Utility function providing information about a regular expression. The
information provided in info::ExprInfo includes the minimum and
maximum width of a pattern match.
Note: successful analysis of an expression with this function does not
imply that compilation of the same expression (via
Database::compile() or Database::compile_multi()) would succeed.
This function may return Ok for regular expressions that
Hyperscan cannot compile.
Note: some per-pattern flags (such as Flags::ALLOWEMPTY and
Flags::SOM_LEFTMOST) are accepted by this call, but as they do not
affect the properties returned in the info::ExprInfo structure,
they will not affect the outcome of this function.
use hyperscan::{expression::{*, info::*}, flags::Flags};
let expr: Expression = "(he)llo".parse()?;
let info = expr.info(Flags::default())?;
assert_eq!(info, ExprInfo {
min_width: ExprWidth(5),
max_width: Some(ExprWidth(5)),
unordered_matches: UnorderedMatchBehavior::OnlyOrdered,
matches_at_eod: MatchAtEndBehavior::WillNeverMatchAtEOD,
});sourcepub fn ext_info(
&self,
flags: Flags,
ext_flags: &ExprExt
) -> Result<ExprInfo, HyperscanCompileError>
pub fn ext_info( &self, flags: Flags, ext_flags: &ExprExt ) -> Result<ExprInfo, HyperscanCompileError>
Utility function providing information about a regular expression, with
extended parameter support. The information provided in info::ExprInfo
includes the minimum and maximum width of a pattern match.
Note: successful analysis of an expression with this function does not
imply that compilation of the same expression (via
Database::compile() or Database::compile_multi()) would succeed.
This function may return Ok for regular expressions that
Hyperscan cannot compile.
Note: some per-pattern flags (such as Flags::ALLOWEMPTY and
Flags::SOM_LEFTMOST) are accepted by this call, but as they do not
affect the properties returned in the info::ExprInfo structure,
they will not affect the outcome of this function.
use hyperscan::{expression::{*, info::*}, flags::Flags};
let expr: Expression = ".*lo".parse()?;
let ext = ExprExt::from_min_length(4);
let info = expr.ext_info(Flags::default(), &ext)?;
assert_eq!(info, ExprInfo {
min_width: ExprWidth(4),
max_width: None,
unordered_matches: UnorderedMatchBehavior::OnlyOrdered,
matches_at_eod: MatchAtEndBehavior::WillNeverMatchAtEOD,
});sourcepub fn compile(
&self,
flags: Flags,
mode: Mode
) -> Result<Database, HyperscanCompileError>
pub fn compile( &self, flags: Flags, mode: Mode ) -> Result<Database, HyperscanCompileError>
Call Database::compile() with None for the platform.
Trait Implementations§
source§impl Clone for Expression
impl Clone for Expression
source§fn clone(&self) -> Expression
fn clone(&self) -> Expression
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for Expression
impl Debug for Expression
source§impl Display for Expression
impl Display for Expression
source§impl FromStr for Expression
impl FromStr for Expression
source§impl Hash for Expression
impl Hash for Expression
source§impl Ord for Expression
impl Ord for Expression
source§fn cmp(&self, other: &Expression) -> Ordering
fn cmp(&self, other: &Expression) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for Expression
impl PartialEq for Expression
source§fn eq(&self, other: &Expression) -> bool
fn eq(&self, other: &Expression) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialOrd for Expression
impl PartialOrd for Expression
source§fn partial_cmp(&self, other: &Expression) -> Option<Ordering>
fn partial_cmp(&self, other: &Expression) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moreimpl Eq for Expression
impl StructuralEq for Expression
impl StructuralPartialEq for Expression
Auto Trait Implementations§
impl RefUnwindSafe for Expression
impl Send for Expression
impl Sync for Expression
impl Unpin for Expression
impl UnwindSafe for Expression
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.