In C, if you wanted to, you could:
#define do {
#define end }
// ...
if (foo == bar) do
foo += 5;
bar /= foo;
end
Is there a way to do something like this in Rust?
No (thankfully). Rust macros must always expand to a complete AST node.
If you need textual substitution, use a tool suited for that job such as sed
, awk
, m4
, the C preprocessor, etc. That can likely be driven by a build script.
There is a toy project that does this, in fact: slag. I have never tried it, though.
It comes with this helpful advice:
Should I use this?
No. Use the default rust syntax.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With