mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-12 02:47:15 +00:00
Previously, the associated types on `NetworkBehaviour` and `ConnectionHandler` carried generic names like `InEvent` and `OutEvent`. These names are _correct_ in that `OutEvent`s are passed out and `InEvent`s are passed in but they don't help users understand how these types are used. In theory, a `ConnectionHandler` could be used separately from `NetworkBehaviour`s but that is highly unlikely. Thus, we rename these associated types to indicate, where the message is going to be sent to: - `NetworkBehaviour::OutEvent` is renamed to `ToSwarm`: It describes the message(s) a `NetworkBehaviour` can emit to the `Swarm`. The user is going to receive those in `SwarmEvent::Behaviour`. - `ConnectionHandler::InEvent` is renamed to `FromBehaviour`: It describes the message(s) a `ConnectionHandler` can receive from its behaviour via `ConnectionHandler::on_swarm_event`. The `NetworkBehaviour` can send it via the `ToSwarm::NotifyHandler` command. - `ConnectionHandler::OutEvent` is renamed to `ToBehaviour`: It describes the message(s) a `ConnectionHandler` can send back to the behaviour via the now also renamed `ConnectionHandlerEvent::NotifyBehaviour` (previously `ConnectionHandlerEvent::Custom`) Resolves: #2854. Pull-Request: #3848.
22 lines
406 B
Rust
22 lines
406 B
Rust
#![deny(warnings)] // Ensure the warnings we produce surface as errors.
|
|
|
|
use libp2p_ping as ping;
|
|
|
|
#[derive(libp2p_swarm::NetworkBehaviour)]
|
|
#[behaviour(out_event = "FooEvent", prelude = "libp2p_swarm::derive_prelude")]
|
|
struct Foo {
|
|
ping: ping::Behaviour,
|
|
}
|
|
|
|
struct FooEvent;
|
|
|
|
impl From<ping::Event> for FooEvent {
|
|
fn from(_: ping::Event) -> Self {
|
|
unimplemented!()
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
|
|
}
|