3

I cannot find how to inject a attribute macro in the result of my attribute macro.

Here is an example of a kind of injection:

use quote::quote;
use proc_macro::TokenStream;

#[proc_macro_attribute]
pub fn my_test(_: TokenStream, item: TokenStream) -> TokenStream {
    let result = quote! {
        #[test]
        #item
    };

    result.into()
}

It generate an error at compile time. Can we call another attribute macro ?

Documentation neither refute nor confirm it.

Corebreaker
  • 357
  • 1
  • 11
  • 4
    What error does it generate? – Frxstrem May 12 '20 at 23:57
  • @Frxstrem An error which say that we cannot do this kind of thing (the trait bound `proc_macro::TokenStream: quote::to_tokens::ToTokens` is not satisfied). The error is not important, the important is : «Can we call another attribute macro ?» – Corebreaker May 13 '20 at 05:48

0 Answers0