4
4
Procedural macros come in one of three flavors:
5
5
6
6
* [ Function-like macros] - ` custom!(...) `
7
- * [ Derive mode macros] - ` #[derive(CustomMode )] `
7
+ * [ Derive macros] - ` #[derive(CustomDerive )] `
8
8
* [ Attribute macros] - ` #[CustomAttribute] `
9
9
10
10
Procedural macros allow you to run code at compile time that operates over Rust
@@ -111,21 +111,21 @@ with curly braces and no semicolon or a different delimiter followed by a
111
111
semicolon. For example, ` make_answer ` from the previous example can be invoked
112
112
as ` make_answer!{} ` , ` make_answer!(); ` or ` make_answer![]; ` .
113
113
114
- ### Derive mode macros
114
+ ### Derive macros
115
115
116
- * Derive mode macros* define new modes for the ` derive ` [ attribute] . These macros
117
- define new [ items] given the token stream of a [ struct] , [ enum] , or [ union] .
118
- They also define [ derive mode helper attributes] .
116
+ * Derive macros* define new inputs for the ` derive ` [ attribute] . These macros
117
+ can create new [ items] given the token stream of a [ struct] , [ enum] , or [ union] .
118
+ They can also define [ derive macro helper attributes] .
119
119
120
- Custom deriver modes are defined by a [ public]   ; [ function] with the
120
+ Custom derive macros are defined by a [ public]   ; [ function] with the
121
121
` proc_macro_derive ` attribute and a signature of ` (TokenStream) -> TokenStream ` .
122
122
123
123
The input [ ` TokenStream ` ] is the token stream of the item that has the ` derive `
124
124
attribute on it. The output [ ` TokenStream ` ] must be a set of items that are
125
125
then appended to the [ module] or [ block] that the item from the input
126
126
[ ` TokenStream ` ] is in.
127
127
128
- The following is an example of a derive mode macro. Instead of doing anything
128
+ The following is an example of a derive macro. Instead of doing anything
129
129
useful with its input, it just appends a function ` answer ` .
130
130
131
131
``` rust,ignore
@@ -138,7 +138,7 @@ pub fn derive_answer_fn(_item: TokenStream) -> TokenStream {
138
138
}
139
139
```
140
140
141
- And then using said derive mode :
141
+ And then using said derive macro :
142
142
143
143
``` rust,ignore
144
144
extern crate proc_macro_examples;
@@ -152,18 +152,18 @@ fn main() {
152
152
}
153
153
```
154
154
155
- #### Derive mode helper attributes
155
+ #### Derive macro helper attributes
156
156
157
- Derive mode macros can add additional [ attributes] into the scope of the [ item]
158
- they are on. Said attributes are called * derive mode helper attributes* . These
157
+ Derive macros can add additional [ attributes] into the scope of the [ item]
158
+ they are on. Said attributes are called * derive macro helper attributes* . These
159
159
attributes are [ inert] , and their only purpose is to be fed into the derive
160
- mode macro that defined them. That said, they can be seen by all macros.
160
+ macro that defined them. That said, they can be seen by all macros.
161
161
162
162
The way to define helper attributes is to put an ` attributes ` key in the
163
163
` proc_macro_derive ` macro with a comma separated list of identifiers that are
164
164
the names of the helper attributes.
165
165
166
- For example, the following derive mode macro defines a helper attribute
166
+ For example, the following derive macro defines a helper attribute
167
167
` helper ` , but ultimately doesn't do anything with it.
168
168
169
169
``` rust,ignore
@@ -177,7 +177,7 @@ pub fn derive_helper_attr(_item: TokenStream) -> TokenStream {
177
177
}
178
178
```
179
179
180
- And then usage on the derive mode on a struct:
180
+ And then usage on the derive macro on a struct:
181
181
182
182
``` rust,ignore
183
183
# #![crate_type="proc-macro"]
@@ -272,15 +272,15 @@ fn invoke4() {}
272
272
[ `derive` ] : attributes.html#derive
273
273
[ `proc_macro` crate ] : ../proc_macro/index.html
274
274
[ Cargo's build scripts ] : ../cargo/reference/build-scripts.html
275
- [ Derive mode macros ] : #derive-mode -macros
275
+ [ Derive macros ] : #derive-macros
276
276
[ Attribute macros ] : #attribute-macros
277
277
[ Function-like macros ] : #function-like-procedural-macros
278
278
[ attribute ] : attributes.html
279
279
[ attributes ] : attributes.html
280
280
[ block ] : expressions/block-expr.html
281
281
[ custom attributes ] : attributes.html
282
282
[ crate type ] : linkage.html
283
- [ derive mode helper attributes ] : #derive-mode -helper-attributes
283
+ [ derive macro helper attributes ] : #derive-macro -helper-attributes
284
284
[ enum ] : items/enumerations.html
285
285
[ inert ] : attributes.html#active-and-inert-attributes
286
286
[ item ] : items.html
0 commit comments