mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-08-01 01:11:58 +00:00
fix(swarm-derive): add bounds to OutEvent
on generic fields (#3393)
This PR isolates the bugfix for the `NetworkBehaviour` derive implementation for structures with generic fields. When `out_event` was not provided, the generated enum was missing the `NetworkBehaviour` impl constraint for the generic variants whilst using the generics for `<Generic>::OutEvent`. Meanwhile I also found that the generated `poll` function `loop`s the sub behaviours and either `return`'s when `Poll::Ready` or `break`'s when `Poll::Pending`. This is a relict from when we still had `NetworkBehaviourEventProcess` which had added a branch within this loop that did not `return` but consume the event and `continue`. This trait was removed a while ago meaning this `loop` is no longer needed.
This commit is contained in:
@@ -308,6 +308,44 @@ fn with_either() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_generics() {
|
||||
#[allow(dead_code)]
|
||||
#[derive(NetworkBehaviour)]
|
||||
#[behaviour(prelude = "libp2p_swarm::derive_prelude")]
|
||||
struct Foo<A, B> {
|
||||
a: A,
|
||||
b: B,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn foo() {
|
||||
require_net_behaviour::<
|
||||
Foo<
|
||||
libp2p_kad::Kademlia<libp2p_kad::record::store::MemoryStore>,
|
||||
libp2p_ping::Behaviour,
|
||||
>,
|
||||
>();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_generics_mixed() {
|
||||
#[allow(dead_code)]
|
||||
#[derive(NetworkBehaviour)]
|
||||
#[behaviour(prelude = "libp2p_swarm::derive_prelude")]
|
||||
struct Foo<A> {
|
||||
a: A,
|
||||
ping: libp2p_ping::Behaviour,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn foo() {
|
||||
require_net_behaviour::<Foo<libp2p_kad::Kademlia<libp2p_kad::record::store::MemoryStore>>>(
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_event_with_either() {
|
||||
use either::Either;
|
||||
|
Reference in New Issue
Block a user