swarm-derive/: Add where clause of behaviour to generated out event (#2819)

When generating the `OutEvent` for a `NetworkBehaviour`, add the `where` clause of the
`NetworkBehaviour` `struct` to the generated `enum`.
This commit is contained in:
Max Inden 2022-08-17 06:43:47 +02:00 committed by GitHub
parent 8dc0188a1d
commit 67266c6a66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -159,7 +159,9 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
let visibility = &ast.vis; let visibility = &ast.vis;
Some(quote! { Some(quote! {
#visibility enum #name #impl_generics { #visibility enum #name #impl_generics
#where_clause
{
#(#fields),* #(#fields),*
} }
}) })

View File

@ -272,7 +272,7 @@ fn custom_event_mismatching_field_names() {
} }
#[test] #[test]
fn where_clause() { fn bound() {
#[allow(dead_code)] #[allow(dead_code)]
#[derive(NetworkBehaviour)] #[derive(NetworkBehaviour)]
struct Foo<T: Copy + NetworkBehaviour> { struct Foo<T: Copy + NetworkBehaviour> {
@ -281,6 +281,19 @@ fn where_clause() {
} }
} }
#[test]
fn where_clause() {
#[allow(dead_code)]
#[derive(NetworkBehaviour)]
struct Foo<T>
where
T: Copy + NetworkBehaviour,
{
ping: libp2p::ping::Ping,
bar: T,
}
}
#[test] #[test]
fn nested_derives_with_import() { fn nested_derives_with_import() {
#[allow(dead_code)] #[allow(dead_code)]