pub struct AllowlistMatcher { /* private fields */ }Expand description
Compiled allowlist that can be queried concurrently.
Exact patterns are stored in a HashSet for O(1) lookup. Glob patterns
(those containing *) are stored in a Vec and scanned linearly after
the hash check misses. Regex patterns (regex: prefix) are stored in a
separate Vec and tried last. This means allowlists with many exact
entries — the common case — pay no linear scan cost.
§Case sensitivity
By default the matcher is case-insensitive: patterns and query values
are both lowercased before comparison (applies to exact and glob patterns
only). Use AllowlistMatcher::new_case_sensitive when exact-case
matching is required. Regex patterns (regex: prefix) are always
case-sensitive; use the (?i) flag inside the pattern for
case-insensitive regex matching.
Implementations§
Source§impl AllowlistMatcher
impl AllowlistMatcher
Sourcepub fn new(patterns: Vec<String>) -> (Self, Vec<String>)
pub fn new(patterns: Vec<String>) -> (Self, Vec<String>)
Build a case-insensitive AllowlistMatcher from a list of pattern strings.
This is the default constructor. Patterns and query values are both
lowercased before comparison, so "Localhost" matches a pattern of
"localhost" and vice-versa.
Each string is treated as a glob if it contains *, otherwise as an
exact match. Patterns that look like regexes (contain ^, $, +,
(, or )) are accepted but a warning message is returned alongside
the matcher so the caller can surface it to the user.
Sourcepub fn new_case_sensitive(patterns: Vec<String>) -> (Self, Vec<String>)
pub fn new_case_sensitive(patterns: Vec<String>) -> (Self, Vec<String>)
Build a case-sensitive AllowlistMatcher from a list of pattern strings.
Use this when exact-case matching is required (e.g. allowlisting a known token value that must not match differently-cased substrings).
Sourcepub fn is_allowed(&self, value: &str) -> bool
pub fn is_allowed(&self, value: &str) -> bool
Returns true if value matches any allowlist entry.
Thread-safe; increments an internal counter when a match is found.
Sourcepub fn match_pattern<'a>(&'a self, value: &str) -> Option<&'a str>
pub fn match_pattern<'a>(&'a self, value: &str) -> Option<&'a str>
Returns the pattern that matches value, or None.
Lookup order: exact hash → glob scan → regex scan. Increments the seen counter when a match is found.
Exact and glob patterns are case-insensitive by default (the matcher
built by new lowercases both patterns and query values
before comparison). Regex patterns (regex: prefix) are always matched
against the original, un-lowercased value regardless of the
case-sensitivity setting; use (?i) inside the pattern for
case-insensitive regex matching.
Sourcepub fn seen_count(&self) -> u64
pub fn seen_count(&self) -> u64
Total number of values that have been allowed through.
Sourcepub fn pattern_count(&self) -> usize
pub fn pattern_count(&self) -> usize
Number of patterns registered (exact + glob + regex).
Auto Trait Implementations§
impl !Freeze for AllowlistMatcher
impl RefUnwindSafe for AllowlistMatcher
impl Send for AllowlistMatcher
impl Sync for AllowlistMatcher
impl Unpin for AllowlistMatcher
impl UnsafeUnpin for AllowlistMatcher
impl UnwindSafe for AllowlistMatcher
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
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