This site goes over six types of syntax extensions in Rust as of 1.0. Decorator
, Modifier
, MultiModifier
, NormalTT
, IdentTT
, and MacroRulesTT
.
Unfortunately, all of its links to documentation for these (and related compiler extension) items appear to be defunct. Indeed, even manually searching the Rust documentation for SyntaxExtension or even the syntax module yields nothing. It still appears to be in the main Rust repository in the master branch, so it's clearly not a matter of just being in the nursery somewhere.
Of note, that page mentions that at some point "soon" (as of 1.0) MultiModifier
and Modifier
may be merged, but due to the disappearing documentation I can't confirm this as of the current Nightly.
The book only documents basic lints and "procedural macros", which seem to be fairly limited in scope.
So, as of now, are there still 6 syntax extension types? Has their documentation been kept up to date in some new location? Do each of them still perform roughly the same function as they did around 1.0?
That site is pretty out of date — it's from before Rust was stabilized. The only "plugins/syntax extensions" supported in Rust 1.20 are macros by example and custom derive, both of which are in The Rust Programming Language. Unstable Rust also has custom attributes and procedural macros, but both of those will likely change before they are stabilized.
A rough mapping of the extension types listed in that site to the current types of macros would be something like:
Examples of macros by example are easy to find (for example std
and the log
crate make extensive use of them). The serde_derive
crate is probably the best example of using custom derive.
UPDATE:
Procederual macros (including custom attributes) were stabilized in Rust 1.30. See https://doc.rust-lang.org/stable/book/ch19-06-macros.html
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