Dependencies
Here is how the standard dependency tree of a modern procedural macro crate is structured:
your_proc_macro_crate
│
▼
proc_macro (Provided by the compiler)
│
▼
proc_macro2 (Wraps proc_macro to allow out-of-compiler executions)
│
▼
┌─┴─────────────┐
▼ ▼
syn quote
(AST Parser) (Code Generator)
- Each library builds on top of the layer below.
- Using
synandquoteincreases macro build times slightly, but greatly simplifies implementation, making macro code safer and much easier to maintain.
- Explain that
proc_macrois provided by the standard distribution, but is restricted to compiler execution. proc_macro2is a standard third-party crate that replicates allproc_macrotypes, but does not depend on the compiler’s private internals. This is why testing libraries or other tools can work with token streams.synandquoteoperate fully onproc_macro2types, allowing seamless integration.