Skip to content
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

Merged
merged 5 commits into from
Aug 8, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 48 additions & 7 deletions swarm-derive/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ fn one_field() {
}

#[allow(dead_code)]
#[allow(unreachable_code)]
fn foo() {
require_net_behaviour::<Foo>();
let _out_event: <Foo as NetworkBehaviour>::OutEvent = unimplemented!();
match _out_event {
FooEvent::Ping(event) => {
let _: libp2p::ping::Event = event;
}
Copy link
Contributor

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?

Suggested change
FooEvent::Ping(event) => {
let _: libp2p::ping::Event = event;
}
FooEvent::Ping(libp2p::ping::Event { .. }) => { }

Copy link
Member Author

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.

}
}
}

Expand All @@ -58,8 +64,17 @@ fn two_fields() {
}

#[allow(dead_code)]
#[allow(unreachable_code)]
fn foo() {
require_net_behaviour::<Foo>();
let _out_event: <Foo as NetworkBehaviour>::OutEvent = unimplemented!();
match _out_event {
FooEvent::Ping(event) => {
let _: libp2p::ping::Event = event;
}
FooEvent::Identify(event) => {
let _: libp2p::identify::IdentifyEvent = event;
}
}
}
}

Expand All @@ -76,8 +91,20 @@ fn three_fields() {
}

#[allow(dead_code)]
#[allow(unreachable_code)]
fn foo() {
require_net_behaviour::<Foo>();
let _out_event: <Foo as NetworkBehaviour>::OutEvent = unimplemented!();
match _out_event {
FooEvent::Ping(event) => {
let _: libp2p::ping::Event = event;
}
FooEvent::Identify(event) => {
let _: libp2p::identify::IdentifyEvent = event;
}
FooEvent::Kad(event) => {
let _: libp2p::kad::KademliaEvent = event;
}
}
}
}

Expand All @@ -93,8 +120,17 @@ fn three_fields_non_last_ignored() {
}

#[allow(dead_code)]
#[allow(unreachable_code)]
fn foo() {
require_net_behaviour::<Foo>();
let _out_event: <Foo as NetworkBehaviour>::OutEvent = unimplemented!();
match _out_event {
FooEvent::Ping(event) => {
let _: libp2p::ping::Event = event;
}
FooEvent::Kad(event) => {
let _: libp2p::kad::KademliaEvent = event;
}
}
}
}

Expand Down Expand Up @@ -268,8 +304,14 @@ fn nested_derives_with_import() {
}

#[allow(dead_code)]
fn bar() {
require_net_behaviour::<Bar>();
#[allow(unreachable_code)]
fn foo() {
let _out_event: <Bar as NetworkBehaviour>::OutEvent = unimplemented!();
match _out_event {
BarEvent::Foo(FooEvent::Ping(event)) => {
let _: libp2p::ping::Event = event;
}
}
}
}

Expand Down Expand Up @@ -434,7 +476,6 @@ fn event_process() {

let mut _swarm: libp2p::Swarm<Foo> = unimplemented!();

// check that the event is bubbled up all the way to swarm
let _ = async {
loop {
match _swarm.select_next_some().await {
Expand Down