swarm-derive/: Generate OutEvent if not provided#2792
Conversation
Generate `NetworkBehaviour::OutEvent` if not provided through `#[behaviour(out_event = "MyOutEvent")]` and event processing is disabled (default).
| /// it will delegate to each `struct` member and return a concatenated array of all addresses | ||
| /// returned by the struct members. | ||
| /// | ||
| /// When creating a custom [`NetworkBehaviour`], you must choose one of two methods to respond to |
There was a problem hiding this comment.
Note that the documentation on NetworkBehaviour now no longer documents NetworkBehaviourEventProcess. My rational being that we will deprecate it anyways, thus there is no use in pointing newcomers to it.
Any objections?
There was a problem hiding this comment.
Maybe I overlooked it, but is there a test that validates for a generated OutEvent that it looks as expected? Could be done by implementing a simple trait for the generated OutEvent or something, e.g. impl TryInto<libp2p::kad::KademliaEvent> for FooEvent (for each inner behaviour).
We could also write a function that matches on an instance of the enum. Should also validate the enum structure and the variant names. |
|
@elenaf9 @thomaseizinger good idea. What do you think of b4e32ed? |
swarm-derive/tests/test.rs
Outdated
| FooEvent::Ping(event) => { | ||
| let _: libp2p::ping::Event = event; | ||
| } |
There was a problem hiding this comment.
Why not just extend the pattern match?
| FooEvent::Ping(event) => { | |
| let _: libp2p::ping::Event = event; | |
| } | |
| FooEvent::Ping(libp2p::ping::Event { .. }) => { } |
There was a problem hiding this comment.
Done in ff63681. Though unfortunately I don't see a way to do the same for the identify and kademlia event given that they are enums.
Description
Generate
NetworkBehaviour::OutEventif not provided through#[behaviour(out_event = "MyOutEvent")]and event processing isdisabled (default).
Extracted from #2751.
As suggested by @elenaf9 in #2784 (review) we would do the following:
NetworkBehaviourEventProcess.NetworkBehaviourEventProcessvia swarm*/: Remove NetworkBehaviourEventProcess and generate OutEvent #2751.What do folks think?
Links to any relevant issues
Open Questions
Change checklist