liveBook · Manning

Attribute macro

As explained in Idiomatic Rust

An attribute macro is a procedural macro attached to an existing item that can accept attribute arguments and generate replacement or additional code.

An attribute macro is a Rust procedural macro attached to an existing item. It can inject code and, unlike the other procedural macro forms, accepts arguments on the attribute. section 8.3

The form is #[MyAttribute]. Derive macros are restricted to struct and enum declarations; function-like procedural macros use macro!(), macro!{}, or macro![]. section 8.3

How Idiomatic Rust covers it

How deep it goes
Defines placement and argument support, but stops short of implementing an attribute macro.
Examples
Shows the attribute form #[MyAttribute] without a worked implementation.
What you can do after
Evaluate its fit by checking whether a macro should attach to an existing item and accept attribute arguments.
How it connects
Compares attribute macros with derive macros, function-like procedural macros, and procedural macros generally.

Also explained in

Compare how 2 books explain attribute macro →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Idiomatic Rust. The section links point to the parts of the book it draws on.