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)
| 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")] |