archunit

Struct Pattern

Source
pub struct Pattern { /* private fields */ }
Expand description

A user pattern compiled to the regular-expression substrate used by every matcher.

Patterns match a complete candidate. Use ** in a glob or .* in a regular expression when a prefix or suffix is intentionally unconstrained.

Implementations§

Source§

impl Pattern

Source

pub fn glob(glob: impl AsRef<str>) -> Result<Self, PatternError>

Compiles a portable, case-sensitive glob.

The supported wildcards are *, **, ?, character classes such as [abc] and [a-z], and negated character classes such as [!0-9]. Backslashes are path separators rather than escapes so one glob behaves the same on every host OS.

Source

pub fn glob_with( glob: impl AsRef<str>, options: PatternOptions, ) -> Result<Self, PatternError>

Compiles a glob with explicit options.

Source

pub fn regex(expression: impl AsRef<str>) -> Result<Self, PatternError>

Compiles a regular expression with complete-candidate matching.

Source

pub fn regex_with( expression: impl AsRef<str>, options: PatternOptions, ) -> Result<Self, PatternError>

Compiles a regular expression with explicit options.

Source

pub fn literal(literal: impl AsRef<str>) -> Result<Self, PatternError>

Compiles a complete literal string, including characters meaningful to globs and regexes.

Source

pub fn literal_with( literal: impl AsRef<str>, options: PatternOptions, ) -> Result<Self, PatternError>

Compiles a complete literal string with explicit options.

Source

pub fn source(&self) -> &str

Returns the pattern exactly as the user supplied it.

Source

pub const fn syntax(&self) -> PatternSyntax

Returns whether this pattern originated as a glob or a regular expression.

Source

pub fn matches(&self, candidate: &str) -> bool

Returns whether the complete normalized candidate matches.

Source

pub fn replace(&self, candidate: &str, replacement: &str) -> String

Replaces this pattern’s match in a normalized candidate.

Rust regex replacement syntax is supported, including $1 and ${name} captures. Because every Pattern is anchored, a matching replacement always covers the complete candidate.

Trait Implementations§

Source§

impl Clone for Pattern

Source§

fn clone(&self) -> Pattern

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Pattern

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Pattern

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.