pub struct ScanPattern { /* private fields */ }Expand description
A pattern rule defining what to scan for and how to categorize matches.
Wraps a compiled regex::bytes::Regex with a Category for
replacement lookups and a human-readable label for reporting.
Both regex and literal patterns are supported. Literal patterns keep their original text and are matched by the scanner’s Aho-Corasick automaton for fast multi-literal scanning.
Implementations§
Source§impl ScanPattern
impl ScanPattern
Sourcepub fn from_regex(
pattern: &str,
category: Category,
label: impl Into<String>,
) -> Result<Self>
pub fn from_regex( pattern: &str, category: Category, label: impl Into<String>, ) -> Result<Self>
Create a pattern from a regex string.
§Errors
Returns SanitizeError::PatternCompileError if the regex is invalid.
§Examples
use sanitize_engine::scanner::ScanPattern;
use sanitize_engine::category::Category;
let pat = ScanPattern::from_regex(
r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}",
Category::Email,
"email_address",
).unwrap();Sourcepub fn from_literal(
literal: &str,
category: Category,
label: impl Into<String>,
) -> Result<Self>
pub fn from_literal( literal: &str, category: Category, label: impl Into<String>, ) -> Result<Self>
Create a pattern from a literal string.
The literal is escaped so that regex metacharacters are matched verbatim.
§Errors
Returns SanitizeError::PatternCompileError if regex compilation fails.
§Examples
use sanitize_engine::scanner::ScanPattern;
use sanitize_engine::category::Category;
let pat = ScanPattern::from_literal(
"sk-proj-abc123secret",
Category::Custom("api_key".into()),
"openai_key",
).unwrap();Sourcepub fn regex_pattern(&self) -> &str
pub fn regex_pattern(&self) -> &str
Return the raw regex pattern string for RegexSet construction.
Trait Implementations§
Source§impl Clone for ScanPattern
impl Clone for ScanPattern
Auto Trait Implementations§
impl Freeze for ScanPattern
impl RefUnwindSafe for ScanPattern
impl Send for ScanPattern
impl Sync for ScanPattern
impl Unpin for ScanPattern
impl UnsafeUnpin for ScanPattern
impl UnwindSafe for ScanPattern
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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