mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-07-02 19:21:37 +00:00
swarm/src/lib: Remove Deref and DerefMut impls on Swarm (#1995)
Remove `Deref` and `DerefMut` implementations previously dereferencing to the `NetworkBehaviour` on `Swarm`. Instead one can access the `NetworkBehaviour` via `Swarm::behaviour` and `Swarm::behaviour_mut`. Methods on `Swarm` can now be accessed directly, e.g. via `my_swarm.local_peer_id()`. Reasoning: Accessing the `NetworkBehaviour` of a `Swarm` through `Deref` and `DerefMut` instead of a method call is an unnecessary complication, especially for newcomers. In addition, `Swarm` is not a smart-pointer and should thus not make use of `Deref` and `DerefMut`, see documentation from the standard library below. > Deref should only be implemented for smart pointers to avoid confusion. https://doc.rust-lang.org/std/ops/trait.Deref.html
This commit is contained in:
@ -70,12 +70,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
// command-line argument, if any.
|
||||
if let Some(addr) = std::env::args().nth(1) {
|
||||
let remote = addr.parse()?;
|
||||
Swarm::dial_addr(&mut swarm, remote)?;
|
||||
swarm.dial_addr(remote)?;
|
||||
println!("Dialed {}", addr)
|
||||
}
|
||||
|
||||
// Tell the swarm to listen on all interfaces and a random, OS-assigned port.
|
||||
Swarm::listen_on(&mut swarm, "/ip4/0.0.0.0/tcp/0".parse()?)?;
|
||||
swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?;
|
||||
|
||||
let mut listening = false;
|
||||
task::block_on(future::poll_fn(move |cx: &mut Context<'_>| {
|
||||
|
Reference in New Issue
Block a user