4 #![crate_type = "proc-macro"]
6 extern crate proc_macro;
10 #[proc_macro_attribute]
11 pub fn foo(attr: TokenStream, f: TokenStream) -> TokenStream {
12 let mut tokens = f.into_iter();
13 assert_eq!(tokens.next().unwrap().to_string(), "#");
14 let next_attr = match tokens.next().unwrap() {
15 TokenTree::Group(g) => g,
19 let fn_tok = tokens.next().unwrap();
20 let ident_tok = tokens.next().unwrap();
21 let args_tok = tokens.next().unwrap();
22 let body = tokens.next().unwrap();
24 let new_body = attr.into_iter()
25 .chain(next_attr.stream().into_iter().skip(1));
31 Group::new(Delimiter::Brace, new_body.collect()).into(),
32 ].into_iter().collect::<TokenStream>();
33 println!("{}", tokens);