Macro macro_attr_2018::macro_attr
source · macro_rules! macro_attr { ( $(#[$($attrs:tt)+])* $(pub $(($($vis:tt)+))?)? enum $($it:tt)+ ) => { ... }; ( $(#[$($attrs:tt)+])* $(pub $(($($vis:tt)+))?)? struct $($it:tt)+ ) => { ... }; ( $(#[$($attrs:tt)+])* $(pub $(($($vis:tt)+))?)? trait $($it:tt)+ ) => { ... }; ( $(#[$($attrs:tt)+])* $vis:vis $keyword:ident $($it:tt)+ ) => { ... }; }
Expand description
When given an item definition, including its attributes, this macro parses said attributes
and dispatches any derivations suffixed with !
to user-defined macros.
This allows multiple macros to process the same item.
Given the following input:
#[derive(Copy, Name!(args...), Clone, Another!, Debug)]
struct Foo;
macro_attr!
will expand to the equivalent of:
#[derive(Copy, Clone, Debug)]
struct Foo;
Name!((args...) struct Foo;);
Another!(() struct Foo;);
Note that macro derives may be mixed with regular derives,
or put in their own #[derive(...)]
attribute.
Also note that macro derive invocations are not passed the other attributes on the item;
input will consist of the arguments provided to the derivation (i.e. (args...)
in this example), the item’s visibility (if any), and the item definition itself.
A macro derivation invoked without arguments will be treated as though
it was invoked with empty parentheses. i.e. #[derive(Name!)]
is equivalent to #[derive(Name!())]
.
A derivation macro may expand to any number of new items derived from the provided input.