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>
impl<C: PatternConfig> TypedPattern<C>
sourcepub fn new(pattern: &str) -> Result<Self, Error>
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>§
Trait Implementations§
source§impl<C> AsRef<Pattern> for TypedPattern<C>
impl<C> AsRef<Pattern> for TypedPattern<C>
source§impl<C: Debug> Debug for TypedPattern<C>
impl<C: Debug> Debug for TypedPattern<C>
source§impl<C> Deref for TypedPattern<C>
impl<C> Deref for TypedPattern<C>
source§impl<'de, C: PatternConfig> Deserialize<'de> for TypedPattern<C>
impl<'de, C: PatternConfig> Deserialize<'de> for TypedPattern<C>
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
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
impl<C> From<TypedPattern<C>> for Pattern
source§fn from(value: TypedPattern<C>) -> Self
fn from(value: TypedPattern<C>) -> Self
Converts to this type from the input type.
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> 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
Mutably borrows from an owned value. Read more