Skip to content

Commit 67266c6

Browse files
authored
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`.
1 parent 8dc0188 commit 67266c6

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

swarm-derive/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
159159
let visibility = &ast.vis;
160160

161161
Some(quote! {
162-
#visibility enum #name #impl_generics {
162+
#visibility enum #name #impl_generics
163+
#where_clause
164+
{
163165
#(#fields),*
164166
}
165167
})

swarm-derive/tests/test.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ fn custom_event_mismatching_field_names() {
272272
}
273273

274274
#[test]
275-
fn where_clause() {
275+
fn bound() {
276276
#[allow(dead_code)]
277277
#[derive(NetworkBehaviour)]
278278
struct Foo<T: Copy + NetworkBehaviour> {
@@ -281,6 +281,19 @@ fn where_clause() {
281281
}
282282
}
283283

284+
#[test]
285+
fn where_clause() {
286+
#[allow(dead_code)]
287+
#[derive(NetworkBehaviour)]
288+
struct Foo<T>
289+
where
290+
T: Copy + NetworkBehaviour,
291+
{
292+
ping: libp2p::ping::Ping,
293+
bar: T,
294+
}
295+
}
296+
284297
#[test]
285298
fn nested_derives_with_import() {
286299
#[allow(dead_code)]

0 commit comments

Comments
 (0)