pub struct Pattern<Kind> { /* private fields */ }Expand description
通用模式匹配结构
支持泛型的模式类型,可以用于不同场景的模式匹配。
§示例
use dhttp_access::pattern::{NormalPattern, LocationPattern};
// 普通模式
let pattern: NormalPattern = "*.log".parse().unwrap();
assert!(pattern.is_match("app.log"));
assert_eq!(pattern.as_str(), "*.log");
// 位置模式
let pattern: LocationPattern = "/api".parse().unwrap();
assert!(pattern.is_match("/api/users"));
assert_eq!(pattern.as_str(), "/api");
// 匹配子字符串
let pattern: NormalPattern = "~ test".parse().unwrap();
assert_eq!(pattern.r#match("this is a test"), Some("test"));Implementations§
Source§impl<Kind> Pattern<Kind>
impl<Kind> Pattern<Kind>
Trait Implementations§
Source§impl AsRef<Pattern<ClientNamePatternKind>> for ClientName
impl AsRef<Pattern<ClientNamePatternKind>> for ClientName
Source§fn as_ref(&self) -> &ClientNamePattern
fn as_ref(&self) -> &ClientNamePattern
Converts this type into a shared reference of the (usually inferred) input type.
Source§impl AsRef<Pattern<NormalPatternKind>> for Method
impl AsRef<Pattern<NormalPatternKind>> for Method
Source§fn as_ref(&self) -> &NormalPattern
fn as_ref(&self) -> &NormalPattern
Converts this type into a shared reference of the (usually inferred) input type.
Source§impl<'de, Kind> Deserialize<'de> for Pattern<Kind>
impl<'de, Kind> Deserialize<'de> for Pattern<Kind>
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
impl<Kind: Eq> Eq for Pattern<Kind>
Source§impl From<Pattern<ClientNamePatternKind>> for ClientName
impl From<Pattern<ClientNamePatternKind>> for ClientName
Source§fn from(value: ClientNamePattern) -> Self
fn from(value: ClientNamePattern) -> Self
Converts to this type from the input type.
Source§impl From<Pattern<NormalPatternKind>> for Method
impl From<Pattern<NormalPatternKind>> for Method
Source§fn from(value: NormalPattern) -> Self
fn from(value: NormalPattern) -> Self
Converts to this type from the input type.
Source§impl From<Pattern<NormalPatternKind>> for Pattern<ClientNamePatternKind>
impl From<Pattern<NormalPatternKind>> for Pattern<ClientNamePatternKind>
Source§fn from(value: Pattern<NormalPatternKind>) -> Self
fn from(value: Pattern<NormalPatternKind>) -> Self
Converts to this type from the input type.
Source§impl From<Pattern<NormalPatternKind>> for Pattern<DomainPatternKind>
impl From<Pattern<NormalPatternKind>> for Pattern<DomainPatternKind>
Source§fn from(value: Pattern<NormalPatternKind>) -> Self
fn from(value: Pattern<NormalPatternKind>) -> Self
Converts to this type from the input type.
Source§impl FromStr for Pattern<ClientNamePatternKind>
impl FromStr for Pattern<ClientNamePatternKind>
Source§impl FromStr for Pattern<DomainPatternKind>
impl FromStr for Pattern<DomainPatternKind>
Source§impl FromStr for Pattern<NormalPatternKind>
impl FromStr for Pattern<NormalPatternKind>
Source§impl FromStr for Pattern<LocationPatternKind>
impl FromStr for Pattern<LocationPatternKind>
Source§impl<Kind: Ord> Ord for Pattern<Kind>
impl<Kind: Ord> Ord for Pattern<Kind>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<Kind: PartialOrd> PartialOrd for Pattern<Kind>
impl<Kind: PartialOrd> PartialOrd for Pattern<Kind>
Auto Trait Implementations§
impl<Kind> Freeze for Pattern<Kind>where
Kind: Freeze,
impl<Kind> RefUnwindSafe for Pattern<Kind>where
Kind: RefUnwindSafe,
impl<Kind> Send for Pattern<Kind>where
Kind: Send,
impl<Kind> Sync for Pattern<Kind>where
Kind: Sync,
impl<Kind> Unpin for Pattern<Kind>where
Kind: Unpin,
impl<Kind> UnsafeUnpin for Pattern<Kind>where
Kind: UnsafeUnpin,
impl<Kind> UnwindSafe for Pattern<Kind>where
Kind: UnwindSafe,
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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