-
Notifications
You must be signed in to change notification settings - Fork 964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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).
@@ -79,16 +79,11 @@ pub(crate) type THandlerOutEvent<THandler> = | |||
/// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm!
swarm-derive/tests/test.rs
Outdated
FooEvent::Ping(event) => { | ||
let _: libp2p::ping::Event = event; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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::OutEvent
if 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
.NetworkBehaviourEventProcess
via swarm*/: Remove NetworkBehaviourEventProcess and generate OutEvent #2751.What do folks think?
Links to any relevant issues
Open Questions
Change checklist