rust-macros
Skill1 starsChanged 40 days agoMITView on GitHub
Rust metaprogramming — declarative macros (macro_rules!) and procedural macros (derive, attribute, function-like) with syn/quote, plus when a macro is the wrong tool. Use when writing or debugging a macro, generating boilerplate, building a derive, or deciding macro vs generics. Triggers: macro_rules!, proc macro, derive macro, syn, quote, cargo expand.
- Installs packages
7 other projects use a version of this.
Adopted by
Most recently taken up by
- rewrite-rs/skillstheir own version, first seen Nov 29, 2026
- po4yka/rust-skillstheir own version, first seen Nov 2, 2026
- full-stack-skills/rust-skillstheir own version, first seen Oct 15, 2026
- Lu1sDV/skillsmdtheir own version, first seen Oct 13, 2026
- botirkhaltaev/botir-skillstheir own version, first seen Jul 24, 2026
- Microbiosis/rust-claude-skillstheir own version, first seen May 28, 2026
Used with
Projects with it also use rust-observability.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
huialiSkillrust-observability
Also in 3 projects that use this
Other versions7 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 7
- rewrite-rs/skills★ 32same name
- full-stack-skills/rust-skills★ 8same name
- po4yka/rust-skills★ 7same name
- botirkhaltaev/botir-skills★ 4same name
- Lu1sDV/skillsmd★ 2same name
- Microbiosis/rust-claude-skills★ 1same name
- dawidpereira/rust-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository42 other files it gives its agents.
- AGENTS.mdAGENTS.md
- addressing-findingsSkill
- auditSkill
- codebase-onboardingSkill
- codex-reviewSkill
- compatibilitySkill
- debuggingSkill
- developSkill
- distributed-racesSkill
- memorySkill
- nix-dev-envSkill
- nix-flakesSkill
- nixosSkill
- nix-packagingSkill
- nix-reviewSkill
- refactoringSkill
- retroSkill
- review-initSkill
- review-rulesSkill
- rust-architecture-reviewSkill
- rust-architectureSkill
- rust-cliSkill
- rust-cloud-nativeSkill
- rust-concurrencySkill
- rust-ecosystemSkill
- rust-embeddedSkill
- rust-errorsSkill
- rust-fintechSkill
- rust-idiomsSkill
- rust-mlSkill
- rust-navigationSkill
- rust-ownershipSkill
- rust-performanceSkill
- rust-pluginsSkill
- rust-reviewSkill
- rust-securitySkill
- rust-testingSkill
- rust-traitsSkill
- rust-unsafeSkill
- rust-webSkill
- specsSkill
- sql-reviewSkill
The file
We split this skill into the rules it gives an agent
2 rules. 0 are common, 1 is distinctive, and 1 is very specific to this project.
0
Common
Most of the 6 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 57
Use macro_rules! when the variation is in the *syntax/shape*.
- Distinctive: line 69
When a macro misbehaves, expand it first.
“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Rust Macros
Macros generate code at compile time. They're powerful and easy to overuse — they hurt readability, tooling, and compile times, and they're harder to debug than ordinary code. Reach for them only when functions, generics, and traits genuinely can't express the thing. Procedural macros are in proc-macros.md.
When to Use
- Eliminating boilerplate that can't be a function/generic (varies in arity or by type shape)
- A custom
#[derive(...)]for your trait - A small embedded DSL (
vec!-like, builder syntax) - Annotating items to transform/register them (attribute macros)
First: do you actually need a macro?
Escalate up this ladder and stop at the first rung that works — each step costs more:
1. a function — runtime values
2. generics + traits — same code over many types (→ rust-traits)
3. macro_rules! (declarative) — same SYNTAX over many forms; variadic; light DSL
4. a procedural macro — parse/transform arbitrary tokens; custom deriveMost "I need a macro" is really generics (rung 2). A macro that just calls a function with fixed args is a function. Don't pay the macro tax for something the type system already does.
Declarative macros — macro_rules!
Pattern-match on syntax and expand. Good for variadic helpers and reducing repetitive call sites.
macro_rules! hashmap {
($($key:expr => $val:expr),* $(,)?) => {{ // trailing-comma tolerant
let mut m = std::collections::HashMap::new();
$( m.insert($key, $val); )* // repetition expands per element
m
}};
}
let m = hashmap!{ "a" => 1, "b" => 2 };- Fragment specifiers name what a metavariable matches:
expr,ident,ty,pat,tt,literal,block,path, … Choose the tightest one (ttis the catch-all, last resort). - Repetition:
$(...)* / + / ?with a separator, mirrored in the body. - Hygiene: identifiers you introduce don't collide with the caller's — a real safety feature declarative macros give you for free.
- Export with
#[macro_export](it lands at crate root).
Use macro_rules! when the variation is in the syntax/shape; if you need to inspect types,
fields, or generate impls from a struct's definition, you've outgrown it → procedural macros.
See what a macro expands to
The #1 debugging tool — read the generated code:
cargo install cargo-expand
cargo expand path::to::module # prints the post-macro sourceWhen a macro misbehaves, expand it first; the bug is almost always visible in the output.
Boundaries
- Procedural macros (derive/attribute/function-like,
syn/quote, errors, testing) → proc-macros.md. - "Same logic over many types" without code generation →
rust-traits(generics/traits first). - A macro that emits
unsafecarries the same obligations →rust-unsafe.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

