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. Literals are escaped and compiled as regex for uniform handling.
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§
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