Skip to content

Commit 8126e66

Browse files
authored
Merge pull request #68 from vks/patch-1
Document how to transition imports of procedural macros
2 parents 8871e7a + fc096f1 commit 8126e66

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/2018/transitioning/modules/macros.md

+31-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Now, you write:
3030

3131
```rust,ignore
3232
// Rust 2018
33-
#![feature(rust_2018_preview, use_extern_macros)]
33+
#![feature(rust_2018_preview)]
3434
3535
use bar::baz;
3636
@@ -41,6 +41,36 @@ fn main() {
4141

4242
This moves `macro_rules` macros to be a bit closer to other kinds of items.
4343

44+
45+
## Procedural macros
46+
47+
When using procedural macros to derive traits, you will have to name the macro
48+
that provides the custom derive. This generally matches the name of the trait,
49+
but check with the documentation of the crate providing the derives to be sure.
50+
51+
For example, with Serde you would have written
52+
53+
```rust,ignore
54+
// Rust 2015
55+
extern crate serde;
56+
#[macro_use] extern crate serde_derive;
57+
58+
#[derive(Serialize, Deserialize)]
59+
struct Bar;
60+
```
61+
62+
Now, you write instead:
63+
64+
```rust,ignore
65+
// Rust 2018
66+
#![feature(rust_2018_preview)]
67+
use serde_derive::{Serialize, Deserialize};
68+
69+
#[derive(Serialize, Deserialize)]
70+
struct Bar;
71+
```
72+
73+
4474
## More details
4575

4676
This only works for macros defined in external crates.

0 commit comments

Comments
 (0)