Writing inclusive derive macros is tedious, this creates provides helper functions that make it easier.
The type_aware_impl
function makes it easy to write derive macros
that take the generics of the underlying type into consideration.
Considering this simple derive macro. ```rust
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
struct Foo
would expand to this:
rust
struct Foo
impl {
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