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
+7-20Lines changed: 7 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -134,25 +134,18 @@ r[macro.proc.derive]
134
134
## Derive macros
135
135
136
136
r[macro.proc.derive.intro]
137
-
*Derive macros* define new inputs for the [`derive` attribute]. These macros
138
-
can create new [items] given the token stream of a [struct], [enum], or [union].
139
-
They can also define [derive macro helper attributes].
137
+
*Derive macros* define new inputs 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].
140
138
141
139
r[macro.proc.derive.def]
142
-
Custom derive macros are defined by a [public] [function] with the
143
-
`proc_macro_derive` attribute and a signature of `(TokenStream) -> TokenStream`.
140
+
Custom derive macros are defined by a [public] [function] with the `proc_macro_derive` attribute and a signature of `(TokenStream) -> TokenStream`.
144
141
145
142
r[macro.proc.derive.namespace]
146
143
The `proc_macro_derive` attribute defines the custom derive in the [macro namespace] in the root of the crate.
147
144
148
145
r[macro.proc.derive.output]
149
-
The input [`TokenStream`] is the token stream of the item that has the `derive`
150
-
attribute on it. The output [`TokenStream`] must be a set of items that are
151
-
then appended to the [module] or [block] that the item from the input
152
-
[`TokenStream`] is in.
146
+
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.
153
147
154
-
The following is an example of a derive macro. Instead of doing anything
155
-
useful with its input, it just appends a function `answer`.
148
+
The following is an example of a derive macro. Instead of doing anything useful with its input, it just appends a function `answer`.
Derive macros can add additional [attributes] into the scope of the [item]
189
-
they are on. Said attributes are called *derive macro helper attributes*. These
190
-
attributes are [inert], and their only purpose is to be fed into the derive
191
-
macro that defined them. That said, they can be seen by all macros.
181
+
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.
192
182
193
183
r[macro.proc.derive.attributes.def]
194
-
The way to define helper attributes is to put an `attributes` key in the
195
-
`proc_macro_derive` macro with a comma separated list of identifiers that are
196
-
the names of the helper attributes.
184
+
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.
197
185
198
-
For example, the following derive macro defines a helper attribute
199
-
`helper`, but ultimately doesn't do anything with it.
186
+
For example, the following derive macro defines a helper attribute `helper`, but ultimately doesn't do anything with it.
0 commit comments