commit | c168310664ab982c8405204c3d8c284621f07112 | [log] [tgz] |
---|---|---|
author | David Tolnay <dtolnay@gmail.com> | Tue Sep 27 08:17:58 2016 -0700 |
committer | David Tolnay <dtolnay@gmail.com> | Tue Sep 27 08:17:58 2016 -0700 |
tree | 96633416718d67904e2e6c0b09374e0530643be0 | |
parent | adf1d5034f5bddd254aca40b520207b0a35a2039 [diff] |
Add From<usize> for Ident, useful for tuple accessors
Parse Rust structs and enums without a Syntex dependency, intended for use with Macros 1.1.
Designed for fast compile time.
syn
(from scratch including all dependencies): 4 secondssyntex
/quasi
/aster
stack: 60+ seconds[dependencies] syn = "0.7"
extern crate syn; let source = " #[derive(Debug, Clone, Eq, PartialEq)] pub struct Item { pub ident: Ident, pub vis: Visibility, pub attrs: Vec<Attribute>, pub generics: Generics, pub body: Body, } "; let ast = syn::parse_macro_input(source).unwrap();
[dependencies] syn = "0.7" quote = "0.1" [lib] rustc-macro = true
#![feature(rustc_macro, rustc_macro_lib)] extern crate rustc_macro; use rustc_macro::TokenStream; extern crate syn; #[macro_use] extern crate quote; #[rustc_macro_derive(MyMacro)] pub fn my_macro(input: TokenStream) -> TokenStream { let source = input.to_string(); // Parse a string of items to an AST let ast = syn::parse_macro_input(&source).unwrap(); // Build the output, possibly using quasi-quotation let expanded = quote! { // ... }; // Parse this back to a token stream and return it expanded.to_string().parse().unwrap() }
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.