I am trying to implement custom derive macros for my traits, and they actually work!
However I have a slight problem. I can't seem to find a way to include generic parameters to the trait.
Specifically, I want to do something like this : #[derive(MyCustomDerive<'a, B, C>)]
Instead, right now I am hard-coding the generics, like so :
let gen = quote! {
impl #impl_generics Graph<'a, V, E> for #name #ty_generics #where_clause {
fn Map(&self) -> &MAP<V, E> {
&self.map
}
...
}
As you can see, I am including 'a, V and E fixed within the quote block, instead of something I want to achieve, which is being able to flexibly derive the trait with the generic types I want.
What I would like is something akin to this :
#[derive(MyCustomDerive<'a, B, C>)]
to result in something equivalent to this
let gen = quote! {
impl #impl_generics Graph<'a, B, C> for #name #ty_generics #where_clause {
fn Map(&self) -> &MAP<B, C> {
&self.map
}
...
}
This would allow me to reserve (of course if necessary) V and E for other things and in my opinion make code more controllable. Thank you for your help!
Update 1 : This is how my derive function looks
pub fn derive(ast: &syn::DeriveInput) -> TokenStream {
let name = &ast.ident;
let generics = &ast.generics;
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
let gen = quote! {
impl #impl_generics Graph<'a, V, E> for #name #ty_generics #where_clause {
fn Map(&self) -> &MAP<V, E> {
&self.map
} ...