Reputation: 3297
So let's say I have a proc macro defined like this:
#[proc_macro]
pub fn my_macro(input: TokenStream) -> TokenStream { ... }
Is there any way to introduce a generic argument? For instance, I would like to be able to do something like this:
#[proc_macro]
pub fn my_macro<T>(input: TokenStream) -> TokenStream {
...
T::do_something_with(input);
...
}
And at the call site:
my_macro::<Foo>! { some input }
Is there any way to achieve something like this?
Upvotes: 2
Views: 71
Reputation: 43782
No, this is not possible, for two reasons:
TokenStream
— not something you can call a function on. The types of the program where the macro is used don't exist yet — they're still being parsed.Upvotes: 4