rust-macros
Skill4 starsChanged 3 months agoApache-2.0View on GitHub
Write declarative and procedural Rust macros. Use when creating macro_rules! macros, derive macros, attribute macros, or function-like proc macros. Covers metavariables, repetitions, TT munching, syn/quote/proc-macro2.
- Installs packages
We split this skill into the rules it gives an agent
1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
0
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 98
Use @ prefix for internal helper rules:
“Common” is measured: kept by at least 6 in 10 of the 4 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
Comprehensive guide based on The Little Book of Rust Macros, the Rust Reference, and procedural macro workshop materials.
When to Use This Skill
- Writing
macro_rules!declarative macros - Creating derive macros (
#[derive(MyTrait)]) - Creating attribute macros (
#[my_attr]) - Creating function-like proc macros (
my_macro!(...)) - Debugging macro expansion issues
- Understanding hygiene, metavariables, and fragment specifiers
Declarative Macros (macro_rules!)
Basic Syntax
macro_rules! say_hello {
() => { println!("Hello!") };
($name:expr) => { println!("Hello, {}!", $name) };
}
say_hello!(); // "Hello!"
say_hello!("world"); // "Hello, world!"Fragment Specifiers
| Specifier | Matches | Example |
expr | Expression | 2 + 2, foo() |
ty | Type | i32, Vec<String> |
ident | Identifier | foo, MyStruct |
pat | Pattern | Some(x), _ |
path | Path | std::io::Error |
tt | Token tree | any single token or (...) [...] {...} group |
stmt | Statement | let x = 1 |
block | Block | { ... } |
item | Item | fn foo() {} |
literal | Literal | 42, "hi" |
lifetime | Lifetime | 'a, 'static |
vis | Visibility | pub, pub(crate) |
meta | Attribute content | derive(Debug) |
Repetitions
macro_rules! vec_of {
($($element:expr),* $(,)?) => {
{
let mut v = Vec::new();
$(v.push($element);)*
v
}
};
}
let v = vec_of![1, 2, 3];Repetition operators:
*— zero or more+— one or more?— zero or one
Multiple Rules (Pattern Matching)
macro_rules! calculate {
(add $a:expr, $b:expr) => { $a + $b };
(mul $a:expr, $b:expr) => { $a * $b };
}Rules are tried top-to-bottom; first match wins.
TT Muncher Pattern
Process tokens one at a time recursively:
macro_rules! count {
() => { 0usize };
($head:tt $($tail:tt)*) => { 1usize + count!($($tail)*) };
}
assert_eq!(count!(a b c d), 4);Internal Rules Pattern
Use @ prefix for internal helper rules:
macro_rules! my_macro {
// Public entry
($($input:tt)*) => { my_macro!(@internal [] $($input)*) };
// Internal accumulator
(@internal [$($acc:tt)*]) => { /* done */ };
(@internal [$($acc:tt)*] $head:tt $($tail:tt)*) => {
my_macro!(@internal [$($acc)* $head] $($tail)*)
};
}Procedural Macros
Setup
Proc macros live in their own crate:
# Cargo.toml
[lib]
proc-macro = true
[dependencies]
syn = { version = "2", features = ["full"] }
quote = "1"
proc-macro2 = "1"Derive Macro
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, DeriveInput};
#[proc_macro_derive(MyTrait)]
pub fn derive_my_trait(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
let name = input.ident;
let expanded = quote! {
impl MyTrait for #name {
fn describe(&self) -> &'static str {
stringify!(#name)
}
}
};
TokenStream::from(expanded)
}Attribute Macro
#[proc_macro_attribute]
pub fn log_calls(attr: TokenStream, item: TokenStream) -> TokenStream {
let input = parse_macro_input!(item as syn::ItemFn);
let name = &input.sig.ident;
let block = &input.block;
let sig = &input.sig;
let expanded = quote! {
#sig {
println!("calling {}", stringify!(#name));
#block
}
};
TokenStream::from(expanded)
}Function-like Proc Macro
#[proc_macro]
pub fn sql(input: TokenStream) -> TokenStream {
let query = input.to_string();
// Parse and validate SQL at compile time
let expanded = quote! { /* ... */ };
TokenStream::from(expanded)
}Debugging Macros
# Expand all macros
cargo expand
# Expand a specific item
cargo expand my_module::MyStruct
# Install cargo-expand
cargo install cargo-expandReference Map
references/declarative-macros.md— macro_rules! patterns, hygiene, scopingreferences/procedural-macros.md— syn/quote, derive/attribute/function-likereferences/macro-patterns.md— TT muncher, push-down, callbacks, counting
Key References
Other versions5 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 5
- full-stack-skills/rust-skills★ 8same name
- Lu1sDV/skillsmd★ 2same name
- po4yka/rust-skills★ 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.
Used alongsideProjects with it also use rust-cli.
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.
tumfSkillrust-cli
Design and implementation guidance for maintainable Rust CLIs with strong ergonomics, machine-friendly behavior, testable structure, and release automation. Use when creating or refactoring a Rust command-line tool, choosing crates like clap/anyhow/tracing/serde_json, improving command UX, adding JSON output, tightening test/release workflows, or making an existing CLI safer for agents and automation.
Also in 3 projects that use this
In this repository80 other files it gives its agents.
- a11y-accessibility-designSkill
- agentic-ui-patternsSkill
- ai-native-ui-designSkill
- ai-ui-anti-patternsSkill
- ai-ui-heuristicsSkill
- calm-technology-uiSkill
- conversion-growth-designSkill
- cross-platform-designSkill
- dark-mode-designSkill
- data-visualizationSkill
- design-systemsSkill
- design-thinking-processSkill
- error-empty-statesSkill
- ethical-design-patternsSkill
- form-uxSkill
- information-architectureSkill
- interaction-design-patternsSkill
- internationalization-uiSkill
- mobile-touch-designSkill
- modal-classes-lifecycleSkill
- modal-container-imagesSkill
- modal-dicts-queuesSkill
- modal-endpointsSkill
- modal-fundamentalsSkill
- modal-gpu-computeSkill
- modal-networkingSkill
- modal-observabilitySkill
- modal-parallel-executionSkill
- modal-sandboxesSkill
- modal-scaling-performanceSkill
- modal-schedulingSkill
- modal-secretsSkill
- modal-serversSkill
- modal-storageSkill
- modal-web-servingSkill
- modal-workspace-adminSkill
- motion-design-principlesSkill
- notifications-permissionsSkill
- onboarding-uxSkill
- rust-api-designSkill
- rust-async-programmingSkill
- rust-cargo-masterySkill
- rust-cli-applicationsSkill
- rust-clippy-lintsSkill
- rust-closures-iteratorsSkill
- rust-compiler-internalsSkill
- rust-concurrencySkill
- rust-design-patternsSkill
- rust-editionsSkill
- rust-embeddedSkill
- rust-error-handlingSkill
- rust-game-developmentSkill
- rust-lifetimes-borrowingSkill
- rust-performanceSkill
- rust-rustdocSkill
- rust-rustup-toolchainSkill
- rust-smart-pointersSkill
- rust-testing-benchmarkingSkill
- rust-type-systemSkill
- rust-unsafe-ffiSkill
- The first 60 shown.
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.

