MCPcopy Create free account
hub / github.com/carllerche/assert-struct / into_pattern

Method into_pattern

assert-struct-macros/src/pattern/regex.rs:33–49  ·  view source on GitHub ↗

Convert this PatternLike into a Pattern, optimizing string literals to PatternRegex. If the expression is a string literal, it will be converted to PatternRegex for compile-time regex compilation. Otherwise, it returns Pattern::Like for runtime pattern matching using the Like trait.

(self)

Source from the content-addressed store, hash-verified

31 /// compile-time regex compilation. Otherwise, it returns Pattern::Like for runtime
32 /// pattern matching using the Like trait.
33 pub(crate) fn into_pattern(self) -> crate::pattern::Pattern {
34 if let syn::Expr::Lit(syn::ExprLit {
35 lit: syn::Lit::Str(lit_str),
36 ..
37 }) = &self.expr
38 {
39 // String literal - compile regex at macro expansion time
40 crate::pattern::Pattern::Regex(PatternRegex {
41 node_id: self.node_id,
42 pattern: lit_str.value(),
43 span: lit_str.span(),
44 })
45 } else {
46 // Expression - use Like trait at runtime
47 crate::pattern::Pattern::Like(self)
48 }
49 }
50}
51
52#[cfg(feature = "regex")]

Callers 1

parseMethod · 0.80

Calls 2

LikeInterface · 0.85
spanMethod · 0.45

Tested by

no test coverage detected