blob: 88025cafc5b554274814bbf6ed4f7fc2be974f47 [file] [log] [blame] [view]
Alex Crichton803720f2017-05-19 19:41:03 -07001# proc-macro2
2
Alex Crichton1bc895e2017-07-05 17:53:06 -07003[Documentation](https://docs.rs/proc-macro2)
Alex Crichton803720f2017-05-19 19:41:03 -07004
Alex Crichton1bc895e2017-07-05 17:53:06 -07005A small shim over the `proc_macro` crate in the compiler intended to multiplex
6the current stable interface (as of 2017-07-05) and the [upcoming richer
Alex Crichton803720f2017-05-19 19:41:03 -07007interface][upcoming].
8
9[upcoming]: https://github.com/rust-lang/rust/pull/40939
10
11The upcoming support has features like:
12
13* Span information on tokens
14* No need to go in/out through strings
15* Structured input/output
16
Alex Crichton1bc895e2017-07-05 17:53:06 -070017The hope is that libraries ported to `proc_macro2` will be trivial to port to
18the real `proc_macro` crate once the support on nightly is stabilize.
Alex Crichton803720f2017-05-19 19:41:03 -070019
Alex Crichton1bc895e2017-07-05 17:53:06 -070020## Usage
21
22This crate by default compiles on the stable version of the compiler. It only
23uses the stable surface area of the `proc_macro` crate upstream in the compiler
24itself. Usage is done via:
25
26```toml
27[dependencies]
28proc-macro2 = "0.1"
29```
30
31followed by
32
33```rust
34extern crate proc_macro;
35extern crate proc_macro2;
36
37#[proc_macro_derive(MyDerive)]
38pub fn my_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
39 let input: proc_macro2::TokenStream = input.into();
40
41 let output: proc_macro2::TokenStream = {
42 /* transform input */
43 };
44
45 output.into()
46}
47```
48
49If you'd like you can enable the `unstable` feature in this crate. This will
50cause it to compile against the **unstable and nightly-only** features of the
51`proc_macro` crate. This in turn requires a nightly compiler. This should help
52preserve span information, however, coming in from the compiler itself.
53
54You can enable this feature via:
55
56```toml
57[dependencies]
58proc-macro2 = { version = "0.1", features = ["unstable"] }
59```
Alex Crichton803720f2017-05-19 19:41:03 -070060
Alex Crichton6dda5422017-10-30 14:07:37 -070061
Alex Crichton803720f2017-05-19 19:41:03 -070062# License
63
Alex Crichtona5aa9b92017-10-30 14:10:07 -070064This project is licensed under either of
Alex Crichton803720f2017-05-19 19:41:03 -070065
Alex Crichton6dda5422017-10-30 14:07:37 -070066 * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
67 http://www.apache.org/licenses/LICENSE-2.0)
68 * MIT license ([LICENSE-MIT](LICENSE-MIT) or
69 http://opensource.org/licenses/MIT)
70
71at your option.
72
73### Contribution
74
75Unless you explicitly state otherwise, any contribution intentionally submitted
76for inclusion in Serde by you, as defined in the Apache-2.0 license, shall be
77dual licensed as above, without any additional terms or conditions.