macros

Guide development of Rust declarative, procedural, and derive macros.

4|2|Updated Dec 28, 2025
One-click install
npx skills add https://github.com/lazygophers/ccplugin --skill macros
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: macros
Source: https://github.com/lazygophers/ccplugin/tree/main/plugins/languages/rust/skills/macros
Command: npx skills add https://github.com/lazygophers/ccplugin --skill macros

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides comprehensive guidance and examples for developing robust Rust macros, including declarative, procedural, and derive macros, enabling advanced code generation and metaprogramming.

Core Features & Use Cases

  • Declarative Macros: Learn to create simple, pattern-matching macros using macro_rules!.
  • Procedural Macros: Understand how to write token-stream manipulating macros for more complex code generation.
  • Derive Macros: Implement custom derive macros to automatically generate trait implementations.
  • Use Case: When building a complex data structure, use a derive macro to automatically implement Debug, Clone, or custom serialization traits, saving significant boilerplate code.

Quick Start

Use the macros skill to generate a basic derive macro for a custom struct.

Frequently Asked Questions about macros

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a Rust derive macro to automatically implement traits for a struct?

To write a Rust derive macro, you define a procedural macro that parses the struct's token stream and generates the trait implementation automatically. This Skill guides you through creating custom derive macros to eliminate manual boilerplate for traits like Debug or Clone.

What is the difference between declarative and procedural macros in Rust?

Declarative macros use `macro_rules!` for simple pattern-matching code generation, while procedural macros manipulate raw token streams directly for complex metaprogramming. This Skill covers both approaches, helping you choose the right macro type for your Rust code generation needs.

How do I start building a procedural macro for token stream manipulation in Rust?

Building a procedural macro involves parsing and transforming token streams to generate Rust code at compile time. This Skill provides step-by-step guidance on setting up procedural macros and manipulating token streams for advanced metaprogramming tasks.

When should I use Rust macros for code generation instead of regular functions?

You should use Rust macros when you need to generate repetitive boilerplate code, implement traits automatically across multiple structs, or perform compile-time metaprogramming that regular functions cannot handle. This Skill demonstrates how to leverage macros to save significant manual coding effort.

Can I automatically generate serialization traits for complex data structures in Rust?

Yes, you can use custom derive macros to automatically generate trait implementations, including custom serialization traits, for complex data structures. This Skill shows how to build derive macros that process your structs and output the required trait implementations.