rust-libp2p
rust-libp2p copied to clipboard
swarm/src/behaviour: Add `AndBehaviour`
Description
To combine two NetworkBehaviour implementations libp2p-swarm should provide a combinator. Contrary to NetworkBehaviour implementation of Either both NetworkBehaviour implementations would be running concurrently.
Motivation
One use-case is when wanting to either enable two NetworkBehaviours or disable both, but never enable one but disable the other.
Toggle<And<BehaviourA, BehaviourB>>
Came up here: https://github.com/n0-computer/iroh/pull/126#discussion_r901236064
Requirements
Open questions
- What is the ideal name? Off the top of my head it should be
And.
Are you planning to do it yourself in a pull request?
No. Though happy to support anyone interested in contributing this.