mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-28 09:11:34 +00:00
*/: Replace Into
with From
(#2169)
Unless restricted by orphan rules, implementing `From` is superior because it implies `Into` but leaves the choice to the user, which one to use. Especially for errors, `From` is convenient because that is what `?` builds on. Co-authored-by: Max Inden <mail@max-inden.de>
This commit is contained in:
@ -71,10 +71,10 @@ impl From<proto::message::ConnectionType> for KadConnectionType {
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<proto::message::ConnectionType> for KadConnectionType {
|
||||
fn into(self) -> proto::message::ConnectionType {
|
||||
impl From<KadConnectionType> for proto::message::ConnectionType {
|
||||
fn from(val: KadConnectionType) -> Self {
|
||||
use proto::message::ConnectionType::*;
|
||||
match self {
|
||||
match val {
|
||||
KadConnectionType::NotConnected => NotConnected,
|
||||
KadConnectionType::Connected => Connected,
|
||||
KadConnectionType::CanConnect => CanConnect,
|
||||
@ -123,13 +123,13 @@ impl TryFrom<proto::message::Peer> for KadPeer {
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<proto::message::Peer> for KadPeer {
|
||||
fn into(self) -> proto::message::Peer {
|
||||
impl From<KadPeer> for proto::message::Peer {
|
||||
fn from(peer: KadPeer) -> Self {
|
||||
proto::message::Peer {
|
||||
id: self.node_id.to_bytes(),
|
||||
addrs: self.multiaddrs.into_iter().map(|a| a.to_vec()).collect(),
|
||||
id: peer.node_id.to_bytes(),
|
||||
addrs: peer.multiaddrs.into_iter().map(|a| a.to_vec()).collect(),
|
||||
connection: {
|
||||
let ct: proto::message::ConnectionType = self.connection_ty.into();
|
||||
let ct: proto::message::ConnectionType = peer.connection_ty.into();
|
||||
ct as i32
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user