Skip to main content

AllowlistMatcher

Struct AllowlistMatcher 

Source
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

Source

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.

Source

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).

Source

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.

Source

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.

Source

pub fn seen_count(&self) -> u64

Total number of values that have been allowed through.

Source

pub fn pattern_count(&self) -> usize

Number of patterns registered (exact + glob + regex).

Source

pub fn is_empty(&self) -> bool

true if no patterns are registered (allowlist is effectively disabled).

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more