pub struct LazyRegex { /* private fields */ }Expand description
A detector pattern whose Regex is compiled on first use, not at load.
Building the full ~1000-pattern corpus up front cost ~450ms (Hyperscan
path) to ~2.3s (portable regex path) on EVERY invocation - even to scan a
one-line file where a single detector fires. The Aho-Corasick literal
prefilter already decides which patterns a given input could match;
deferring each pattern’s Regex::build until that prefilter (or a
keyword-gated fallback sweep) actually needs it means a typical scan
compiles a handful of patterns instead of all of them. Startup drops to
the cost of the AC automaton plus the few regexes that fire.
as_str() returns the source with no compilation, so the Hyperscan /
GPU literal-set builders that only read pattern text stay zero-cost.
The compiled Arc<Regex> is shared across clones of the same pattern
(the cell is Arc-shared) and, for the detector flavor, across all
detectors with an identical pattern string via the process-wide regex
cache (compiler_compile::shared_regex) - so the ~6-15% duplicate
regexes in the corpus (AIza..., xoxb-..., JWT shapes) still compile
at most once each.
Implementations§
Source§impl LazyRegex
impl LazyRegex
Sourcepub fn detector(src: impl Into<Arc<str>>) -> Self
pub fn detector(src: impl Into<Arc<str>>) -> Self
A detector pattern: case-insensitive, CRLF-aware, DFA-size-bounded -
identical to the eager shared_regex_compile build, and routed
through the same process-wide dedup cache on first use.
Sourcepub fn plain(src: impl Into<Arc<str>>) -> Self
pub fn plain(src: impl Into<Arc<str>>) -> Self
A plain pattern with default flags - matches the old Regex::new
used for homoglyph-expanded fallback variants.
Sourcepub fn get(&self) -> &Regex
pub fn get(&self) -> &Regex
Compile-on-first-use. A pattern that fails to compile (impossible for
the curated corpus - the contracts suite compiles every embedded
detector on each CI run, and the --detectors quality gate
AST-parses + size-bounds user patterns) degrades to a never-matching
regex with a loud error! log rather than panicking: a scanner that
can’t build one rule must still not crash the whole scan.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LazyRegex
impl RefUnwindSafe for LazyRegex
impl Send for LazyRegex
impl Sync for LazyRegex
impl Unpin for LazyRegex
impl UnsafeUnpin for LazyRegex
impl UnwindSafe for LazyRegex
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more