derive-elves

Writing inclusive derive macros is tedious, this creates provides helper functions that make it easier.

type aware impl

The type_aware_impl function makes it easy to write derive macros that take the generics of the underlying type into consideration.

Example

Considering this simple derive macro. ```rust

[procmacroderive(Append)]

pub fn push(inputstream: TokenStream) -> TokenStream { let inputtype = parsemacroinput!(input_stream as DeriveInput);

let ident = &input_type.ident;

type_aware_impl(
    quote! {
        impl<T: Append<T>> Append<T> for #ident {
            fn append(&self, l: T) {
                todo!()
            }
        }
    },
    &input_type,
)

} The the following anotated struct, rust

[derive(Append)]

struct Foo { bar: S } would expand to this: rust struct Foo { bar: S }

impl, S: ToString> Append for Foo { fn append(&self, l: T) { todo!() } } The above also works for more complex patterns, like the following: rust impl Trait for & #ident rust impl Trait for &mut #ident rust impl Trait for [#ident] rust impl Trait for (#ident, A, B, C) ```

License: MIT