Skip to content

Commit

Permalink
swarm-derive/: Add where clause of behaviour to generated out event (#…
Browse files Browse the repository at this point in the history
…2819)

When generating the `OutEvent` for a `NetworkBehaviour`, add the `where` clause of the
`NetworkBehaviour` `struct` to the generated `enum`.
  • Loading branch information
mxinden committed Aug 17, 2022
1 parent 8dc0188 commit 67266c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion swarm-derive/src/lib.rs
Expand Up @@ -159,7 +159,9 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
let visibility = &ast.vis;

Some(quote! {
#visibility enum #name #impl_generics {
#visibility enum #name #impl_generics
#where_clause
{
#(#fields),*
}
})
Expand Down
15 changes: 14 additions & 1 deletion swarm-derive/tests/test.rs
Expand Up @@ -272,7 +272,7 @@ fn custom_event_mismatching_field_names() {
}

#[test]
fn where_clause() {
fn bound() {
#[allow(dead_code)]
#[derive(NetworkBehaviour)]
struct Foo<T: Copy + NetworkBehaviour> {
Expand All @@ -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]
fn nested_derives_with_import() {
#[allow(dead_code)]
Expand Down

0 comments on commit 67266c6

Please sign in to comment.