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

Disambiguate calls to NetworkBehaviour::inject_event #1543

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Version ???

- `libp2p-core-derive`: Disambiguate calls to `NetworkBehaviour::inject_event`.
[PR 1543](https://github.com/libp2p/rust-libp2p/pull/1543)

- `libp2p-floodsub`: Allow sent messages seen as subscribed.
[PR 1520](https://github.com/libp2p/rust-libp2p/pull/1520)

Expand Down
4 changes: 2 additions & 2 deletions misc/core-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
}

Some(match field.ident {
Some(ref i) => quote!{ #elem => self.#i.inject_event(peer_id, connection_id, ev) },
None => quote!{ #elem => self.#field_n.inject_event(peer_id, connection_id, ev) },
Some(ref i) => quote!{ #elem => #trait_to_impl::inject_event(&mut self.#i, peer_id, connection_id, ev) },
None => quote!{ #elem => #trait_to_impl::inject_event(&mut self.#field_n, peer_id, connection_id, ev) },
})
});

Expand Down
32 changes: 32 additions & 0 deletions misc/core-derive/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,35 @@ fn where_clause() {
bar: T,
}
}

#[test]
fn nested_derives_with_import() {
use libp2p::swarm::NetworkBehaviourEventProcess;

#[allow(dead_code)]
#[derive(NetworkBehaviour)]
struct Foo {
ping: libp2p::ping::Ping,
}

#[allow(dead_code)]
#[derive(NetworkBehaviour)]
struct Bar {
foo: Foo,
}

impl NetworkBehaviourEventProcess<libp2p::ping::PingEvent> for Foo {
fn inject_event(&mut self, _: libp2p::ping::PingEvent) {
}
}

impl NetworkBehaviourEventProcess<()> for Bar {
fn inject_event(&mut self, _: ()) {
}
}

#[allow(dead_code)]
fn bar() {
require_net_behaviour::<Bar>();
}
}