> How does one go about acquiring an intuition for when to use or not use them?
Truthfully, I don't know. In this particular case, the benefits seem really clear: we get safety and performance increases.
But here's a caveat: the particular reason why this works well for regexes is because the common use case is to write the string literal corresponding to the regex into your program. This is what allows the macro facilities to kick in. For example, if the regex is derived from user input at runtime, then the `regex!` macro can't be used.
i.e., you can't do this:
let restr = "a*";
let re = regex!(restr);
The `regex!` macro must accept a string literal (or another macro invocation that produces a string literal).
I see. So maybe if you had a fixed XSD or XSLT at compile time you could emit a faster but specialized parser or transformer. But maybe that wouldn't work out so well in practice.
I did find an interesting slide deck from the scala universe that mentions something like F# type providers (among other things) as possible applications.
> How does one go about acquiring an intuition for when to use or not use them?
Truthfully, I don't know. In this particular case, the benefits seem really clear: we get safety and performance increases.
But here's a caveat: the particular reason why this works well for regexes is because the common use case is to write the string literal corresponding to the regex into your program. This is what allows the macro facilities to kick in. For example, if the regex is derived from user input at runtime, then the `regex!` macro can't be used.
i.e., you can't do this:
The `regex!` macro must accept a string literal (or another macro invocation that produces a string literal).