pub enum Pattern {
Text(String),
Regex {
regex: String,
flags: String,
},
}Expand description
String-or-regex pattern. Wire-compatible: plain JSON string ↔
Pattern::Text; tagged object {regex, flags} ↔ Pattern::Regex.
Case-insensitive 模式跟 TS v1.5 c5i-d 1:1: regex 缺 /i flag 自动注入;
text 走 eq_ignore_ascii_case 模拟 toLowerCase strict equal.
Variants§
Text(String)
Plain literal string. Empty string never matches anything (TS
resolve-selector.ts:178 if (pattern === '') return false).
Regex
Compiled-on-call regex. flags defaults to “i” when absent to
satisfy v1.5 c5i-d maestro parity.
Implementations§
Source§impl Pattern
impl Pattern
Sourcepub fn regex<P: Into<String>>(pattern: P) -> Self
pub fn regex<P: Into<String>>(pattern: P) -> Self
Construct a regex pattern. Auto-injects i flag if absent.
Sourcepub fn regex_with_flags<P: Into<String>, F: Into<String>>(
pattern: P,
flags: F,
) -> Self
pub fn regex_with_flags<P: Into<String>, F: Into<String>>( pattern: P, flags: F, ) -> Self
Construct a regex pattern with explicit flags.
Sourcepub fn compile(&self) -> Result<CompiledPattern, Error>
pub fn compile(&self) -> Result<CompiledPattern, Error>
Compile the wire-form pattern into a hot-path-ready CompiledPattern.
One-time cost (~5-50 μs for regex compile, ~ns for text); the
resulting CompiledPattern matches in 5-50 ns per call — the
regex compile gets fully amortized after just one re-use.
Use match_text for one-shot SDK convenience; use match_text_compiled
inside any hot resolver loop after Pattern::compile() once.
Returns Err(regex::Error) only for malformed regex patterns;
text patterns are infallible.