Skip to main content

PatternRegistry

Struct PatternRegistry 

Source
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

Source

pub fn new() -> Self

Create a new empty pattern registry

Source

pub fn register(&mut self, key: &str, pattern: &str) -> Result<()>

Register a new pattern

Returns an error if the pattern is invalid regex.

Source

pub fn register_many(&mut self, patterns: &[(&str, &str)]) -> Result<()>

Register multiple patterns at once

Source

pub fn is_match(&self, key: &str, text: &str) -> bool

Check if a pattern matches the given text

Source

pub fn any_match(&self, keys: &[&str], text: &str) -> bool

Check if any of the given patterns match

Source

pub fn all_match(&self, keys: &[&str], text: &str) -> bool

Check if all of the given patterns match

Source

pub fn find_all(&self, key: &str, text: &str) -> Vec<PatternMatch>

Find all matches for a pattern in text

Source

pub fn find_any(&self, keys: &[&str], text: &str) -> Vec<PatternMatch>

Find matches from any of the given patterns

Source

pub fn find_first(&self, key: &str, text: &str) -> Option<PatternMatch>

Get the first match for a pattern

Source

pub fn get(&self, key: &str) -> Option<&Regex>

Get pattern by key

Source

pub fn contains(&self, key: &str) -> bool

Check if a pattern key exists

Source

pub fn len(&self) -> usize

Get the number of registered patterns

Source

pub fn is_empty(&self) -> bool

Check if the registry is empty

Source

pub fn keys(&self) -> impl Iterator<Item = &str>

Get all pattern keys

Source

pub fn merge(&mut self, other: PatternRegistry)

Merge another registry into this one

Source

pub fn merged(registries: Vec<PatternRegistry>) -> Self

Create a new registry by merging multiple registries

Trait Implementations§

Source§

impl Default for PatternRegistry

Source§

fn default() -> PatternRegistry

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.