
rust-macros
Design, name, implement, debug, test, and review Rust declarative and procedural macros, including macrorules matchers and repetition, hygiene, $crate paths, derive, attribute and function-like macros, proc-macro crate naming, syn parsing, quote generation, diagnostics, cargo-expand, doctests, and trybuild. Use when users need compile-time code generation, a Rust DSL, or guidance choosing -derive versus -macros; keep ordinary trait, generic, or handwritten APIs outside macros unless generation has a clear maintenance benefit.
- Installs
- 98
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/full-stack-skills/rust-skills --skill rust-macros- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads rust-macros automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Rust Macros
Use macros for syntax transformation or mechanical generation that functions, traits, generics, and build scripts cannot express cleanly. Keep the generated API smaller and more stable than the macro implementation.
Scope and Routing
Use this skill for macro_rules!, declarative DSLs, derive macros, attribute macros, function-like procedural macros, parsing, token generation, hygiene, diagnostics, and expansion tests.
Route ordinary generic design to rust-stable, crate layout and proc-macro companion crates to rust-workspace, feature and publishing policy to rust-cargo-build, compile-fail strategy to rust-testing, use of the third-party Lombok-like derives to rust-lombok-macros, and UniFFI export/derive usage plus generated foreign bindings to rust-uniffi-building.
Workflow
1. Prove a macro is the right boundary
Write representative invocations and expected expansions first. Prefer a function, trait, derive already provided by the ecosystem, or small handwritten implementation when it keeps diagnostics and navigation clearer. Define supported syntax, edition, MSRV, generated names, visibility, error cases, and semver surface.
2. Choose the smallest macro category
| Need | Mechanism |
|---|---|
| Repeat or match Rust token patterns | macro_rules! |
| Implement a trait for an annotated type | derive procedural macro |
| Transform an annotated item | attribute procedural macro |
| Parse a custom token invocation | function-like procedural macro |
Use a dedicated proc-macro = true crate for procedural macros. Put shared runtime traits and types in a normal library crate so generated code does not depend on private proc-macro implementation details.
3. Name procedural-macro crates by their public surface
Treat the suffix as an API promise, not a compiler requirement:
| Public macro surface | Preferred package suffix | Examples |
|---|---|---|
Only #[proc_macro_derive] entry points | -derive or the established family spelling such as _derive | serde_derive |
| A broader suite, especially attribute or function-like macros, or mixed macro kinds | -macros | tokio-macros, actix-macros |
| Unclear or unspecified macro scope | Avoid singular -macro; choose a more descriptive name | — |
Choose -derive when every public entry point is a derive macro. The crate may expose several closely related derives; the deciding factor is macro kind, not the exact count. Choose -macros when the crate exposes attribute macros, function-like macros, mixed macro kinds, or intentionally serves as the package family's general macro collection.
Do not publish both <name>-derive and <name>-macros by default. A single proc-macro crate can register any number of derive, attribute, and function-like macros. Prefer one of these layouts:
<name> # public runtime API or facade; may re-export macros
<name>-derive # derive-only proc-macro crate
<name> # public runtime API or facade; may re-export macros
<name>-macros # general proc-macro collection
<name>-macro-core # optional normal library for parsing and generation logic
Split -derive and -macros into separate published crates only when users can adopt them independently and the split materially reduces dependencies or compile time, separates release or compatibility policies, or isolates distinct ownership boundaries. Keep their exported macro names and responsibilities non-overlapping. Do not split merely by macro kind or for naming symmetry.
Before publishing, also:
- Follow the separator already used by the crate family; Cargo package names may contain
-or_, while Rust crate identifiers normalize hyphens to underscores. - Prefer a facade crate and feature-gated re-exports when most users should not depend on the implementation crate directly.
- Treat a published crate rename as a migration with ecosystem and semver cost; choose the intended long-term scope early, but do not claim planned macro kinds before they exist.
4. Implement declarative macros hygienically
#[macro_export]
macro_rules! string_list {
($($value:expr),* $(,)?) => {{
let mut output = ::std::vec::Vec::new();
$(output.push(::std::string::ToString::to_string(&$value));)*
output
}};
}
- Put specific matcher arms before general arms.
- Use the correct fragment specifier such as
expr,ident,ty,pat,item,meta,path, ortt. - Support an optional trailing separator only when the public syntax intends it.
- Use
$cratefor paths into the defining crate. - Avoid repeated evaluation, hidden moves, surprising control flow, and identifiers that collide with caller code.
- Avoid quadratic TT munchers for large inputs; prefer repetitions or procedural parsing when token volume matters.
5. Parse procedural macros structurally
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, DeriveInput};
#[proc_macro_derive(Describe)]
pub fn derive_describe(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
let name = input.ident;
quote! {
impl Describe for #name {
fn type_name() -> &'static str {
stringify!(#name)
}
}
}
.into()
}
- Parse with
synor a purpose-built parser rather than token strings. - Preserve spans and combine
syn::Errorvalues so users receive multiple useful diagnostics. - Generate paths that work after dependency renaming when the public contract requires it.
- Preserve generics, lifetimes, const parameters, where clauses, attributes, and visibility.
- Do not panic on invalid user input; emit compile errors at the relevant span.
6. Test the public expansion contract
Use several layers:
cargo fmt --all --check
cargo check --workspace --all-targets --all-features
cargo test --workspace --all-targets --all-features
cargo clippy --workspace --all-targets --all-features -- -D warnings
cargo expand --package example-crate
- Runtime and doctest cases prove successful generated behavior.
trybuildor equivalent UI tests lock accepted and rejected syntax plus diagnostics.- Expansion snapshots are review aids, not the only correctness gate.
- Test generic, lifetime, visibility, renamed-dependency, no-std, feature, and edition combinations that the macro claims to support.
Nightly trace_macros! is an optional diagnostic tool, not a stable default.
Read Macro Reference for matcher and procedural-macro details. Read Execution Scenarios for representative requests.
Review Checklist
- Could a function, trait, or derive replace the macro?
- Is caller input evaluated exactly as documented?
- Are
$crate, spans, generics, and visibility handled correctly? - Can invalid input trigger a proc-macro panic?
- Does generated unsafe code expose a documented safe contract?
- Are compile-fail diagnostics tested without overspecifying unstable wording?
- Does the generated public API create an intentional semver commitment?
Completion Criteria
- Define supported syntax and expected expansion before implementation.
- Use the smallest suitable macro category.
- Preserve hygiene, spans, generics, visibility, and edition compatibility.
- Cover successful expansions and rejected syntax with caller-shaped tests.
- Pass formatting, check, tests, and Clippy on supported configurations.
Upstream Sources
Data Privacy
This skill does not collect, store, or transmit user data. Generated code may embed input literals, so review expansion output for secrets before publishing artifacts.
FAQ
What does the rust-macros skill do?
Design, name, implement, debug, test, and review Rust declarative and procedural macros, including macrorules matchers and repetition, hygiene, $crate paths, derive, attribute and function-like macros, proc-macro crate naming, syn parsing, quote generation, diagnostics, cargo-expand, doctests, and trybuild. Use when users need compile-time code generation, a Rust DSL, or guidance choosing -derive versus -macros; keep ordinary trait, generic, or handwritten APIs outside macros unless generation has a clear maintenance benefit.
How do I install rust-macros?
Run npx skills add https://github.com/full-stack-skills/rust-skills --skill rust-macros in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/rust-macros/ (personal) or .claude/skills/rust-macros/ (project).
Which AI agents can use rust-macros?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is rust-macros safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains rust-macros?
It is published by full-stack-skills in full-stack-skills/rust-skills. It has 98 recorded installs.
More from full-stack-skills/rust-skills
rust-testing
full-stack-skills/rust-skills
Design, implement, and validate Rust tests, including unit, integration, doctest, compile-fail, property, fuzz, benchmark, coverage, async, concurrency, process, daemon, IPC, terminal, platform, and hardware-facing test strategies. Use when users ask for Rust test architecture, flaky-test diagnosis, coverage gates, benchmarks, trybuild, cargo-nextest, real-process tests, or failure-path verification.
rust-concurrency
full-stack-skills/rust-skills
Open the skill to read its SKILL.md instructions.
rust-style-clippy
full-stack-skills/rust-skills
Open the skill to read its SKILL.md instructions.
rust-performance
full-stack-skills/rust-skills
Measure, profile, optimize, and regression-test Rust performance across latency, throughput, CPU, allocations, memory, binary size, and compile time using representative workloads, Criterion, iai-callgrind, cargo-flamegraph, samply, DHAT, heap or pprof tools, cargo-bloat, cargo-llvm-lines, and build timings. Use when users report slow Rust code, high memory or CPU, large binaries, noisy benchmarks, tail-latency regressions, or need performance budgets and evidence-backed optimization.
rust-code-review
full-stack-skills/rust-skills
Review Rust changes for correctness, memory and thread safety, error semantics, unnecessary allocation or cloning, lock scope, API compatibility, test gaps, documentation, and dependency risk, applying the Rust API Guidelines checklist (C-PANIC, C-UNWRAP, C-TRANSMUTE, C-BOOL, C-NEWTYPE, C-COMMON-TRAITS, C-CONVERT, C-SEALED, C-NON-EXHAUSTIVE). Use when reviewing Rust diffs, pull requests, libraries, unsafe boundaries, or production incidents; report actionable findings by severity before summaries, route automated formatting or lint policy to rust-style-clippy, and route API shape decisions (trait sealing, error taxonomy, newtype design, builder patterns) to rust-api-design.
rust-cargo-build
full-stack-skills/rust-skills
Open the skill to read its SKILL.md instructions.
Popular backend & apis skills
find-skills
vercel-labs/skills
Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express interest in extending capabilities. This skill should be used when the user is looking for functionality that might exist as an installable skill.
entra-app-registration
microsoft/azure-skills
Guides Microsoft Entra ID app registration, OAuth 2.0 authentication, and MSAL integration. USE FOR: create app registration, register Azure AD app, configure OAuth, set up authentication, add API permissions, generate service principal, MSAL example, console app auth, Entra ID setup, Azure AD authentication. DO NOT USE FOR: Key Vault secrets (use azure-keyvault-expiration-audit), general Azure resource security guidance.
google-agents-cli-adk-code
google/agents-cli
This skill should be used when the user wants to "write agent code", "build an agent with ADK", "add a tool", "create a callback", "define an agent", "use state management" — in a project that needs ADK (Agent Development Kit) API patterns and code examples. It provides a quick reference for agent types, tool definitions, orchestration patterns, callbacks, state management, the graph Workflow API, and reference recipes to study. Do NOT use for scaffolding (use google-agents-cli-scaffold) or deployment (use google-agents-cli-deploy).
embedded-captions
heygen-com/hyperframes
Add captions or subtitles to an existing single-subject talking-head video without editing the footage. Use for plain verbatim captions, cinematic captions embedded behind the subject, VFX captions, “炸/特效/酷炫字幕,” or a named identity from the 35-style catalog. Route by visual identity, not by backend engine. The quiet anchor rail is the default; embed every word only when the user explicitly wants a fully cinematic treatment. The workflow runs locally end to end, including transcription and subject matting; split multi-shot footage before applying it.
entra-agent-id
microsoft/azure-skills
Provision Microsoft Entra Agent Identity Blueprints, BlueprintPrincipals, and per-instance Agent Identities via Microsoft Graph, and configure OAuth 2.0 token exchange (fmipath, OBO, cross-tenant) including the Microsoft Entra SDK for AgentID sidecar. USE FOR: Agent Identity Blueprint, BlueprintPrincipal, agent OAuth, fmipath token exchange, agent OBO, Workload Identity Federation for agents, polyglot agent auth, Microsoft.Identity.Web.AgentIdentities. DO NOT USE FOR: standard Entra app registration (use entra-app-registration), Microsoft Foundry agent authoring (use microsoft-foundry).
neon
neondatabase/agent-skills
Overview of Neon, a complete set of cloud backend primitives around Lakebase Postgres: Auth, Object Storage, Functions, the AI Gateway, and Realtime. Start here to choose Neon for undecided login, files, APIs, and LLM calls, set up the CLI or MCP server, and follow the branch-first workflow. Use when building an app or backend on Neon, or when "Neon" or "Lakebase Postgres" is mentioned. Child skill neon-postgres wins for an existing DATABASEURL, SQL, schema, inspect, or search. Child skill neon-auth wins for login, users, sessions, identity routing, and Managed Better Auth setup. Child skill neon-realtime wins for live queries in reactive apps and agents. Also use for object storage, S3, buckets, serverless functions, function triggers, cron, AI gateway, LLM calls, realtime, logs, Loki, Grafana, observability, postgres, database, backend, Claimable Neon, neon.new, or a no-signup database.