The Rust Regex crate offers the regex!
syntax extension which makes it possible to compile a regex during the standard compile time. This is good in two ways:
- we don't need to do that work during runtime (better program performance)
- if our regex is malformed, the compiler can tell us during compilation instead of triggering a runtime panic
Unfortunately, the docs say:
WARNING: The
regex!
compiler plugin is orders of magnitude slower than the normalRegex::new(...)
usage. You should not use the compiler plugin unless you have a very special reason for doing so.
This sounds like a completely different regex engine is used for regex!
than for Regex::new()
. Why isn't regex!()
just a wrapper for Regex::new()
to combine the advantages from both worlds? As I understand it, these syntax-extension compiler plugins can execute arbitrary code; why not Regex::new()
?