#macros

proc-macro2

A stable implementation of the upcoming new proc_macro API. Comes with an option, off by default, to also reimplement itself in terms of the upstream unstable API.

43 releases

0.4.18 Sep 6, 2018
0.4.15 Aug 29, 2018
0.4.9 Jul 22, 2018
0.3.1 Mar 31, 2018
0.1.2 Jul 14, 2017

#3 in Procedural macro helpers

Download history 44514/week @ 2018-06-14 54550/week @ 2018-06-21 59557/week @ 2018-06-28 58605/week @ 2018-07-05 65820/week @ 2018-07-12 72449/week @ 2018-07-19 74067/week @ 2018-07-26 76634/week @ 2018-08-02 75373/week @ 2018-08-09 76371/week @ 2018-08-16 75840/week @ 2018-08-23 81046/week @ 2018-08-30 86049/week @ 2018-09-06

300,274 downloads per month
Used in 4,482 crates (214 directly)

MIT/Apache

113KB
3K SLoC

proc-macro2

Build Status Latest Version Rust Documentation

A small shim over the proc_macro crate in the compiler intended to multiplex the stable interface as of 1.15.0 and the interface as of 1.30.0.

New features added in Rust 1.30.0 include:

  • Span information on tokens
  • No need to go in/out through strings
  • Structured input/output

Libraries ported to proc_macro2 can retain support for older compilers while continuing to get all the nice benefits of using a 1.30.0+ compiler.

Usage

This crate compiles on all 1.15.0+ stable compilers and usage looks like:

[dependencies]
proc-macro2 = "0.4"

followed by

extern crate proc_macro;
extern crate proc_macro2;

#[proc_macro_derive(MyDerive)]
pub fn my_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    let input: proc_macro2::TokenStream = input.into();

    let output: proc_macro2::TokenStream = {
        /* transform input */
    };

    output.into()
}

The 1.30.0 compiler is automatically detected and its interfaces are used when available.

Unstable Features

proc-macro2 supports exporting some methods from proc_macro which are currently highly unstable, and are not stabilized in the first pass of proc_macro stabilizations. These features are not exported by default. Minor versions of proc-macro2 may make breaking changes to them at any time.

To enable these features, the procmacro2_semver_exempt config flag must be passed to rustc.

RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo build

Note that this must not only be done for your crate, but for any crate that depends on your crate. This infectious nature is intentional, as it serves as a reminder that you are outside of the normal semver guarantees.

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Serde by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

  • build build.rs