pub struct PatternRegistry { /* private fields */ }Expand description
Registry for managing compiled regex patterns
Patterns are compiled once and stored for efficient repeated matching.
§Example
use gatekpr_patterns::PatternRegistry;
let mut registry = PatternRegistry::new();
registry.register("email", r"[\w\.-]+@[\w\.-]+\.\w+").unwrap();
assert!(registry.is_match("email", "test@example.com"));Implementations§
Source§impl PatternRegistry
impl PatternRegistry
Sourcepub fn register(&mut self, key: &str, pattern: &str) -> Result<()>
pub fn register(&mut self, key: &str, pattern: &str) -> Result<()>
Register a new pattern
Returns an error if the pattern is invalid regex.
Sourcepub fn register_many(&mut self, patterns: &[(&str, &str)]) -> Result<()>
pub fn register_many(&mut self, patterns: &[(&str, &str)]) -> Result<()>
Register multiple patterns at once
Sourcepub fn is_match(&self, key: &str, text: &str) -> bool
pub fn is_match(&self, key: &str, text: &str) -> bool
Check if a pattern matches the given text
Sourcepub fn any_match(&self, keys: &[&str], text: &str) -> bool
pub fn any_match(&self, keys: &[&str], text: &str) -> bool
Check if any of the given patterns match
Sourcepub fn all_match(&self, keys: &[&str], text: &str) -> bool
pub fn all_match(&self, keys: &[&str], text: &str) -> bool
Check if all of the given patterns match
Sourcepub fn find_all(&self, key: &str, text: &str) -> Vec<PatternMatch>
pub fn find_all(&self, key: &str, text: &str) -> Vec<PatternMatch>
Find all matches for a pattern in text
Sourcepub fn find_any(&self, keys: &[&str], text: &str) -> Vec<PatternMatch>
pub fn find_any(&self, keys: &[&str], text: &str) -> Vec<PatternMatch>
Find matches from any of the given patterns
Sourcepub fn find_first(&self, key: &str, text: &str) -> Option<PatternMatch>
pub fn find_first(&self, key: &str, text: &str) -> Option<PatternMatch>
Get the first match for a pattern
Sourcepub fn merge(&mut self, other: PatternRegistry)
pub fn merge(&mut self, other: PatternRegistry)
Merge another registry into this one
Sourcepub fn merged(registries: Vec<PatternRegistry>) -> Self
pub fn merged(registries: Vec<PatternRegistry>) -> Self
Create a new registry by merging multiple registries
Trait Implementations§
Source§impl Default for PatternRegistry
impl Default for PatternRegistry
Source§fn default() -> PatternRegistry
fn default() -> PatternRegistry
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for PatternRegistry
impl RefUnwindSafe for PatternRegistry
impl Send for PatternRegistry
impl Sync for PatternRegistry
impl Unpin for PatternRegistry
impl UnsafeUnpin for PatternRegistry
impl UnwindSafe for PatternRegistry
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