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
#[macro_export] macro_rules! make_add_macro { ( ($d:tt) name: $name_:ident; type: $type_:path; body: {$($body:item)+} ) => { #[macro_export] macro_rules! $name_ { ($type:path) => { impl $type_ for $type { $($body)+ } }; ($type:path, $d($lifetimes:lifetime),+ $d($generics:ident),*) => { impl<$d($lifetimes,)+ $d($generics,)*> $type_ for $type { $($body)+ } } } }; ( name: $name:ident; type: $type:path; body: {$($body:item)+} ) => { make_add_macro! { ($) name: $name; type: $type; body: { $($body)+ } } } }