rust-macroslisted
Install: claude install-skill po4yka/rust-skills
# Rust macros
## Purpose
Write and debug a `macro_rules!` macro, a derive macro, or an attribute macro. Three rules
decide whether a macro compiles at all: textual scope, hygiene, and the follow-set
restrictions on fragment specifiers. This skill covers those three, the crate split a
procedural macro needs, and the paths and bounds its output must emit. It stops at the macro.
Which crates a workspace holds and which way its normal dependencies point belong to
`rust-crate-architecture`.
Every error message and every number below comes from rustc 1.97.0, 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 |
| 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 | — |
A macro costs compile time, a second crate in the procedural case, diagnostics that point at
the invocation instead of the defect, and an IDE that cannot look inside. Take a non-macro row
when one fits.
## Route the symptom
| Symptom or task | Section |
| --- | --- |
| `error: cannot find macro ... in this scope`