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
One thing worth highlighting is that we're preferring to say that we
"declare" (rather than "define") derive macro helper attributes. A
definition is something that says what something is. For these
attributes, though, we're just declaring that they exist.
Copy file name to clipboardExpand all lines: src/procedural-macros.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -134,10 +134,10 @@ r[macro.proc.derive]
134
134
## The `proc_macro_derive` attribute
135
135
136
136
r[macro.proc.derive.intro]
137
-
The *`proc_macro_derive`[attribute][attributes]* defines a *derive macro*which defines an input for the [`derive` attribute]. These macros can create new [items]given the token stream of a [struct], [enum], or [union]. They can also define [derive macro helper attributes].
137
+
The *`proc_macro_derive`[attribute][attributes]* defines a *derive macro*that can be be invoked by the [`derive` attribute]. These macros are given the token stream of a [struct], [enum], or [union] definition and can emit new [items] after it. They can also define [derive macro helper attributes].
138
138
139
139
> [!EXAMPLE]
140
-
> The following is an example of a derive macro. Instead of doing anything useful with its input, it just appends a function`answer`.
140
+
> This derive macro ignores its input and appends tokens that define a function.
141
141
>
142
142
> <!-- ignore: test doesn't support proc-macro -->
143
143
> ```rust,ignore
@@ -151,7 +151,7 @@ The *`proc_macro_derive` [attribute][attributes]* defines a *derive macro* which
The `proc_macro_derive` attribute may only be specified once on a function.
189
189
190
190
r[macro.proc.derive.namespace]
191
-
The `proc_macro_derive` attribute publicly defines the custom derive in the [macro namespace] in the root of the crate with the name given in the attribute.
191
+
The `proc_macro_derive` attribute publicly defines the derive macro in the [macro namespace] in the root of the crate using the name given in the attribute.
192
192
193
193
r[macro.proc.derive.output]
194
-
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.
194
+
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. These items are appended following the input item within the same [module] or [block].
195
195
196
196
r[macro.proc.derive.attributes]
197
197
### Derive macro helper attributes
198
198
199
199
r[macro.proc.derive.attributes.intro]
200
-
Derive macros can add additional [attributes] into the scope of the [item] they are on. Said attributes are called *derive macro helper attributes*. These attributes are [inert], and their only purpose is to be fed into the derive macro that defined them. That said, they can be seen by all macros.
200
+
Derive macros can add *derive macro helper attributes* to the scope of the [item]. These [attributes] are [inert]. While their purpose is to be used by the macro that declared them, they can be seen by any macro.
201
201
202
-
r[macro.proc.derive.attributes.def]
203
-
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.
202
+
r[macro.proc.derive.attributes.decl]
203
+
A helper attribute for a derive macro is declared by adding its identifier to the `attributes`list in the `proc_macro_derive` attribute.
204
204
205
205
> [!EXAMPLE]
206
-
> The following derive macro defines a helper attribute `helper`, but ultimately doesn't do anything with it.
206
+
> This declares a helper attribute and then ignores it.
207
207
>
208
208
> <!-- ignore: test doesn't support proc-macro -->
0 commit comments