Function futures_await_syn::parse [] [src]

pub fn parse<T>(tokens: TokenStream) -> Result<T, ParseError> where
    T: Synom

Parse tokens of source code into the chosen syn data type.

This is preferred over parsing a string because tokens are able to preserve information about where in the user's code they were originally written (the "span" of the token), possibly allowing the compiler to produce better error messages.

Examples

Be careful when using this code, it's not being tested!
extern crate proc_macro;
use proc_macro::TokenStream;

extern crate syn;

#[macro_use]
extern crate quote;

use syn::DeriveInput;

#[proc_macro_derive(MyMacro)]
pub fn my_macro(input: TokenStream) -> TokenStream {
    // Parse the tokens into a syntax tree
    let ast: DeriveInput = syn::parse(input).unwrap();

    // Build the output, possibly using quasi-quotation
    let expanded = quote! {
        /* ... */
    };

    // Parse back to a token stream and return it
    expanded.parse().unwrap()
}