You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/procedural-macros.md
+53-44Lines changed: 53 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -138,41 +138,49 @@ The *`proc_macro_derive` [attribute][attributes]* defines a *derive macro* which
138
138
139
139
r[macro.proc.derive.def]
140
140
Custom derive macros are defined by a [public] [function] with the `proc_macro_derive` attribute and a signature of `(TokenStream) -> TokenStream`.
141
+
> [!EXAMPLE]
142
+
> The following is an example of a derive macro. Instead of doing anything useful with its input, it just appends a function `answer`.
143
+
>
144
+
> <!-- ignore: test doesn't support proc-macro -->
The `proc_macro_derive` attribute defines the custom derive in the [macro namespace] in the root of the crate.
144
173
145
174
r[macro.proc.derive.output]
146
175
The input [`TokenStream`] is the token stream of the item that has the `derive` attribute on it. The output [`TokenStream`] must be a set of items that are then appended to the [module] or [block] that the item from the input [`TokenStream`] is in.
147
176
148
-
The following is an example of a derive macro. Instead of doing anything useful with its input, it just appends a function `answer`.
@@ -183,29 +191,30 @@ Derive macros can add additional [attributes] into the scope of the [item] they
183
191
r[macro.proc.derive.attributes.def]
184
192
The way to define helper attributes is to put an `attributes` key in the `proc_macro_derive` macro with a comma separated list of identifiers that are the names of the helper attributes.
185
193
186
-
For example, the following derive macro defines a helper attribute `helper`, but ultimately doesn't do anything with it.
0 commit comments