rust-macros
Installation
SKILL.md
Contains Shell Commands
This skill contains shell command directives (!`command`) that may execute system commands. Review carefully before installing.
Rust macros
Every quoted message and number below comes from rustc, cargo, and Clippy 1.98.1, edition 2024.
Decide whether you need a macro
| You want | Reach for | Why not a macro |
|---|---|---|
| One body, many types | A generic function, or a blanket impl | Monomorphization already does this |
| A constant computed at build time | const fn, or a const { } block |
You add no syntax |
| Code generated from a schema or a data file | build.rs plus include! |
The input is not Rust tokens |
| Items or an expression chosen per target or feature | cfg_select! (std, Rust 1.95+) |
No hand-written macro and no cfg-if dependency |
| Repeated syntax inside one crate | macro_rules! |
— |
| The same trait impl per type, derived from the type's shape | A derive macro | — |
| An item rewritten or wrapped | An attribute macro (procedural) | — |