I'm trying to write a macro for implementing a trait on a type. However, some of the types have const generic arguments, so i would like to be able to pass these as a second argument to the macro. The following is my attempt, where the first usage works but the second doesn't:
macro_rules! impl_trait {
($type:ty,$generics:tt) => {
impl<$generics> FooTrait for $type {}
};
}
struct FooBar<T>(T);
impl_trait!(FooBar<T>, T);
struct Bar<const N: usize>;
impl_trait!(Bar<N>, const N: usize);
I have tried other ways of denoting the second argument, but none of them have worked.