-
Notifications
You must be signed in to change notification settings - Fork 999
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
swarm/src/lib: Remove Deref and DerefMut impls on Swarm #1995
Conversation
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
FWIW, I am in favor of this change. I always found |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No objections from my side.
I would deem 5 days enough as a review period, thus merging now. Thanks for the reviews. Happy for future comments / suggestions. |
Sorry I didn't see this sooner and comment. But I wonder if #2006 isn't the better approach. Keep the deref/deref_mut and instead removing the swarm methods/events in favor of more |
@dvc94ch In my understanding, that is a orthogonal issue. With this patch, we simply force users to explicitely type As a result, we were able to remove the unintuitve associated functions for calling others things on Improving the NetworkBehaviour and all the things we talked about in the other thread are still possible as far as I can see :) |
I think there are other cases where using But yes, I think it's orthogonal, I was just worried about too many api changes for users. |
Thx so much for doing this! |
Remove
Deref
andDerefMut
implementations previously dereferencingto the
NetworkBehaviour
onSwarm
. Instead one can access theNetworkBehaviour
viaSwarm::behaviour
andSwarm::behaviour_mut
.Methods on
Swarm
can now be accessed directly, e.g. viamy_swarm.local_peer_id()
.Reasoning: Accessing the
NetworkBehaviour
of aSwarm
throughDeref
and
DerefMut
instead of a method call is an unnecessary complication,especially for newcomers. In addition,
Swarm
is not a smart-pointerand should thus not make use of
Deref
andDerefMut
, see documentationfrom the standard library below.
https://doc.rust-lang.org/std/ops/trait.Deref.html
For the reasons mentioned above I would consider this breaking change worth doing. This has been shortly discussed in #1073 in the past. What do people think?