swarm-derive/: Allow for templated behaviours (#2907)

This patch fixes an issue where we couldn't use type parameters on a behaviour
with a custom out event that had different type parameters.
This commit is contained in:
Thomas Eizinger
2022-09-17 00:57:41 +10:00
committed by GitHub
parent c81b06a9b2
commit 2025de3ef0
6 changed files with 82 additions and 4 deletions

View File

@@ -100,7 +100,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
.iter()
.map(|field| {
let ty = &field.ty;
quote! {#name #ty_generics: From< <#ty as #trait_to_impl>::OutEvent >}
quote! {#name: From< <#ty as #trait_to_impl>::OutEvent >}
})
.collect::<Vec<_>>();
(name, definition, from_clauses)
@@ -537,6 +537,12 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
})
});
let out_event_reference = if out_event_definition.is_some() {
quote! { #out_event_name #ty_generics }
} else {
quote! { #out_event_name }
};
// Now the magic happens.
let final_quote = quote! {
#out_event_definition
@@ -545,7 +551,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
#where_clause
{
type ConnectionHandler = #connection_handler_ty;
type OutEvent = #out_event_name #ty_generics;
type OutEvent = #out_event_reference;
fn new_handler(&mut self) -> Self::ConnectionHandler {
use #into_connection_handler;