mcpField
R
rust-macros

rust-macros

github.com/pluginagentmarketplaceDevelopment118 installsUpdated 42w ago
Repository

About rust-macros

A Rust macros skill for developers learning and using declarative `macro_rules!` and procedural macros. It includes examples, fragment specifiers, expansion tools, and troubleshooting guidance.

Key features

  1. 01Declarative macro examples
  2. 02Procedural macro patterns
  3. 03Fragment specifier reference
  4. 04Macro expansion with cargo expand
  5. 05Hygiene and ordering troubleshooting

Use cases

  1. 01Creating reusable Rust macro_rules! helpers
  2. 02Building derive procedural macros
  3. 03Inspecting macro expansions while debugging

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/pluginagentmarketplace/custom-plugin-rust --skill rust-macros

After installing, type/rust-macrosin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

assets/
config.yaml
macro-example.rs
schema.json
references/
GUIDE.md
PATTERNS.md
scripts/
validate.py

Details

From the project README

Rust Macros Skill

Master Rust's macro system: declarative macros (macro_rules!) and procedural macros.

Quick Start

Declarative Macros
macro_rules! vec_of_strings {
    ($($x:expr),* $(,)?) => {
        vec![$($x.to_string()),*]
    };
}

let v = vec_of_strings!["a", "b", "c"];
Fragment Specifiers
SpecifierMatches
identIdentifier
exprExpression
tyType
patPattern
ttToken tree
literalLiteral
Repetition
macro_rules! hashmap {
    ($($key:expr => $value:expr),* $(,)?) => {{
        let mut map = std::collections::HashMap::new();
        $(map.insert($key, $value);)*
        map
    }};
}

let m = hashmap! { "one" => 1, "two" => 2 };

Procedural Macros

[lib]
proc-macro = true

[dependencies]
syn = { version = "2", features = ["full"] }
quote = "1"
Derive Macro
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, DeriveInput};

#[proc_macro_derive(HelloMacro)]
pub fn hello_derive(input: TokenStream) -> TokenStream {
    let input = parse_macro_input!(input as DeriveInput);
    let name = input.ident;

    quote! {
        impl HelloMacro for #name {
            fn hello() {
                println!("Hello from {}!", stringify!(#name));
            }
        }
    }.into()
}

Debugging

cargo expand              # Expand all macros
cargo expand main         # Expand specific

Troubleshooting

ProblemSolution
Hygiene issuesUse $crate::
Order mattersDefine before use

Resources

Comments

Markdown supported