Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

swarm-derive/: Don't fail when ignored fields are first #2569

Closed
mxinden opened this issue Mar 17, 2022 · 1 comment · Fixed by #2570
Closed

swarm-derive/: Don't fail when ignored fields are first #2569

mxinden opened this issue Mar 17, 2022 · 1 comment · Fixed by #2570
Labels
bug difficulty:moderate getting-started Issues that can be tackled if you don't know the internals of libp2p very well help wanted

Comments

@mxinden
Copy link
Member

mxinden commented Mar 17, 2022

The NetworkBehaviour derive macro seems to fail when the #[behaviour(ignore)] fields are not the very last fields.

E.g. while the first here fails, the second succeeds:

/// Behaviour type.
#[derive(libp2p::NetworkBehaviour)]
#[behaviour(out_event = "BehaviourEvent", event_process = true)]
pub struct Behaviour<Types: IpfsTypes> {
    #[behaviour(ignore)]
    repo: Arc<Repo<Types>>,
    // mdns: Toggle<TokioMdns>,
    kademlia: Kademlia<MemoryStore>,
    #[behaviour(ignore)]
    kad_subscriptions: SubscriptionRegistry<KadResult, String>,
    bitswap: Bitswap,
    ping: Ping,
    identify: Identify,
    pubsub: Pubsub,
    pub swarm: SwarmApi,
}
/// Behaviour type.
#[derive(libp2p::NetworkBehaviour)]
#[behaviour(event_process = true)]
pub struct Behaviour<Types: IpfsTypes> {
    // mdns: Toggle<TokioMdns>,
    kademlia: Kademlia<MemoryStore>,
    bitswap: Bitswap,
    ping: Ping,
    identify: Identify,
    pubsub: Pubsub,
    pub swarm: SwarmApi,
    #[behaviour(ignore)]
    repo: Arc<Repo<Types>>,
    #[behaviour(ignore)]
    kad_subscriptions: SubscriptionRegistry<KadResult, String>,
}

See rs-ipfs/rust-ipfs#499 (comment) for a failure in the wild.

@mxinden mxinden added bug difficulty:moderate help wanted getting-started Issues that can be tackled if you don't know the internals of libp2p very well labels Mar 17, 2022
@rand0m-cloud
Copy link
Contributor

Specifically, the errors generated from the bad example are the following:

error[E0599]: no method named `into_inner` found for struct `KademliaHandler` in the current scope
  --> src/p2p/behaviour.rs:25:10
   |
25 | #[derive(libp2p::NetworkBehaviour)]
   |          ^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `KademliaHandler<QueryId>`
   |
   = note: this error originates in the derive macro `libp2p::NetworkBehaviour` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no method named `into_inner` found for struct `KademliaHandlerProto` in the current scope
  --> src/p2p/behaviour.rs:25:10
   |
25 | #[derive(libp2p::NetworkBehaviour)]
   |          ^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `KademliaHandlerProto<QueryId>`
   |
   = note: this error originates in the derive macro `libp2p::NetworkBehaviour` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0599`.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug difficulty:moderate getting-started Issues that can be tackled if you don't know the internals of libp2p very well help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants