1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*!
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.
```ignore
#[proc_macro_derive(Append)]
pub fn push(input_stream: TokenStream) -> TokenStream {
let input_type = parse_macro_input!(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,
```ignore
#[derive(Append)]
struct Foo<S: ToString> {
bar: S
}
```
would expand to this:
```ignore
struct Foo<S: ToString> {
bar: S
}
impl<T: Append<T>, S: ToString> Append<T> for Foo<S> {
fn append(&self, l: T) {
todo!()
}
}
```
The above also works for more complex patterns,
like the following:
```ignore
impl Trait for & #ident
```
```ignore
impl Trait for &mut #ident
```
```ignore
impl Trait for [#ident]
```
```ignore
impl Trait for (#ident, A, B, C)
```
*/
pub use *;