Struct relay_pattern::TypedPattern

source ·
pub struct TypedPattern<C = DefaultPatternConfig> { /* private fields */ }
Expand description

A Pattern with compile time encoded PatternConfig.

Encoding the pattern configuration allows context dependent serialization and usage of patterns and ensures a consistent usage of configuration options throught the code.

Often repeated configuration can be grouped into custom and importable configurations.

struct MetricConfig;

impl relay_pattern::PatternConfig for MetricConfig {
    const CASE_INSENSITIVE: bool = false;
    // More configuration ...
}

type MetricPattern = relay_pattern::TypedPattern<MetricConfig>;

let pattern = MetricPattern::new("[cd]:foo/bar").unwrap();
assert!(pattern.is_match("c:foo/bar"));

Implementations§

source§

impl<C: PatternConfig> TypedPattern<C>

source

pub fn new(pattern: &str) -> Result<Self, Error>

Creates a new TypedPattern using the provided pattern and config C.

use relay_pattern::{Pattern, TypedPattern, CaseInsensitive};

let pattern = TypedPattern::<CaseInsensitive>::new("foo*").unwrap();
assert!(pattern.is_match("FOOBAR"));

// Equivalent to:
let pattern = Pattern::builder("foo*").case_insensitive(true).build().unwrap();
assert!(pattern.is_match("FOOBAR"));

Methods from Deref<Target = Pattern>§

source

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

Returns true if the pattern matches the passed string.

Trait Implementations§

source§

impl<C> AsRef<Pattern> for TypedPattern<C>

source§

fn as_ref(&self) -> &Pattern

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<C: Debug> Debug for TypedPattern<C>

source§

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

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

impl<C> Deref for TypedPattern<C>

source§

type Target = Pattern

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'de, C: PatternConfig> Deserialize<'de> for TypedPattern<C>

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<C> From<TypedPattern<C>> for Pattern

source§

fn from(value: TypedPattern<C>) -> Self

Converts to this type from the input type.
source§

impl<C> Serialize for TypedPattern<C>

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<C> Freeze for TypedPattern<C>

§

impl<C> RefUnwindSafe for TypedPattern<C>
where C: RefUnwindSafe,

§

impl<C> Send for TypedPattern<C>
where C: Send,

§

impl<C> Sync for TypedPattern<C>
where C: Sync,

§

impl<C> Unpin for TypedPattern<C>
where C: Unpin,

§

impl<C> UnwindSafe for TypedPattern<C>
where C: UnwindSafe,

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,