mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-14 02:21:21 +00:00
{core,swarm}/: Don't require Transport: Clone
and take &mut
(#2529)
Previously `libp2p-swarm` required a `Transport` to be `Clone`. Methods on `Transport`, e.g. `Transport::dial` would take ownership, requiring e.g. a `Clone::clone` before calling `Transport::dial`. The requirement of `Transport` to be `Clone` is no longer needed in `libp2p-swarm`. E.g. concurrent dialing can be done without a clone per dial. This commit removes the requirement of `Clone` for `Transport` in `libp2p-swarm`. As a follow-up methods on `Transport` no longer take ownership, but instead a mutable reference (`&mut self`). On the one hand this simplifies `libp2p-swarm`, on the other it simplifies implementations of `Transport`.
This commit is contained in:
@ -497,7 +497,10 @@ where
|
||||
type ListenerUpgrade = EitherFuture<A::ListenerUpgrade, B::ListenerUpgrade>;
|
||||
type Dial = EitherFuture<A::Dial, B::Dial>;
|
||||
|
||||
fn listen_on(self, addr: Multiaddr) -> Result<Self::Listener, TransportError<Self::Error>> {
|
||||
fn listen_on(
|
||||
&mut self,
|
||||
addr: Multiaddr,
|
||||
) -> Result<Self::Listener, TransportError<Self::Error>> {
|
||||
use TransportError::*;
|
||||
match self {
|
||||
EitherTransport::Left(a) => match a.listen_on(addr) {
|
||||
@ -513,7 +516,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn dial(self, addr: Multiaddr) -> Result<Self::Dial, TransportError<Self::Error>> {
|
||||
fn dial(&mut self, addr: Multiaddr) -> Result<Self::Dial, TransportError<Self::Error>> {
|
||||
use TransportError::*;
|
||||
match self {
|
||||
EitherTransport::Left(a) => match a.dial(addr) {
|
||||
@ -529,7 +532,10 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn dial_as_listener(self, addr: Multiaddr) -> Result<Self::Dial, TransportError<Self::Error>>
|
||||
fn dial_as_listener(
|
||||
&mut self,
|
||||
addr: Multiaddr,
|
||||
) -> Result<Self::Dial, TransportError<Self::Error>>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
|
Reference in New Issue
Block a user