mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-13 18:11:22 +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:
@ -1,3 +1,8 @@
|
|||||||
|
# 0.10.4 [unreleased]
|
||||||
|
|
||||||
|
- Implement `From<io::Error> for ProtocolError` instead of `Into`.
|
||||||
|
[PR 2169](https://github.com/libp2p/rust-libp2p/pull/2169)
|
||||||
|
|
||||||
# 0.10.3 [2021-03-17]
|
# 0.10.3 [2021-03-17]
|
||||||
|
|
||||||
- Update dependencies.
|
- Update dependencies.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "multistream-select"
|
name = "multistream-select"
|
||||||
description = "Multistream-select negotiation protocol for libp2p"
|
description = "Multistream-select negotiation protocol for libp2p"
|
||||||
version = "0.10.3"
|
version = "0.10.4"
|
||||||
authors = ["Parity Technologies <admin@parity.io>"]
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/libp2p/rust-libp2p"
|
repository = "https://github.com/libp2p/rust-libp2p"
|
||||||
|
@ -391,9 +391,9 @@ impl From<io::Error> for ProtocolError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<io::Error> for ProtocolError {
|
impl From<ProtocolError> for io::Error {
|
||||||
fn into(self) -> io::Error {
|
fn from(err: ProtocolError) -> Self {
|
||||||
if let ProtocolError::IoError(e) = self {
|
if let ProtocolError::IoError(e) = err {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
io::ErrorKind::InvalidData.into()
|
io::ErrorKind::InvalidData.into()
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
- Update dependencies.
|
- Update dependencies.
|
||||||
|
|
||||||
|
- Implement `From<io::Error> for YamuxError` instead of `Into`.
|
||||||
|
[PR 2169](https://github.com/libp2p/rust-libp2p/pull/2169)
|
||||||
|
|
||||||
# 0.33.0 [2021-07-12]
|
# 0.33.0 [2021-07-12]
|
||||||
|
|
||||||
- Update dependencies.
|
- Update dependencies.
|
||||||
|
@ -360,9 +360,9 @@ where
|
|||||||
#[error("yamux error: {0}")]
|
#[error("yamux error: {0}")]
|
||||||
pub struct YamuxError(#[from] yamux::ConnectionError);
|
pub struct YamuxError(#[from] yamux::ConnectionError);
|
||||||
|
|
||||||
impl Into<io::Error> for YamuxError {
|
impl From<YamuxError> for io::Error {
|
||||||
fn into(self: YamuxError) -> io::Error {
|
fn from(err: YamuxError) -> Self {
|
||||||
match self.0 {
|
match err.0 {
|
||||||
yamux::ConnectionError::Io(e) => e,
|
yamux::ConnectionError::Io(e) => e,
|
||||||
e => io::Error::new(io::ErrorKind::Other, e)
|
e => io::Error::new(io::ErrorKind::Other, e)
|
||||||
}
|
}
|
||||||
|
@ -233,13 +233,13 @@ impl GossipsubRpc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<rpc_proto::Rpc> for GossipsubRpc {
|
impl From<GossipsubRpc> for rpc_proto::Rpc {
|
||||||
/// Converts the RPC into protobuf format.
|
/// Converts the RPC into protobuf format.
|
||||||
fn into(self) -> rpc_proto::Rpc {
|
fn from(rpc: GossipsubRpc) -> Self {
|
||||||
// Messages
|
// Messages
|
||||||
let mut publish = Vec::new();
|
let mut publish = Vec::new();
|
||||||
|
|
||||||
for message in self.messages.into_iter() {
|
for message in rpc.messages.into_iter() {
|
||||||
let message = rpc_proto::Message {
|
let message = rpc_proto::Message {
|
||||||
from: message.source.map(|m| m.to_bytes()),
|
from: message.source.map(|m| m.to_bytes()),
|
||||||
data: Some(message.data),
|
data: Some(message.data),
|
||||||
@ -253,7 +253,7 @@ impl Into<rpc_proto::Rpc> for GossipsubRpc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// subscriptions
|
// subscriptions
|
||||||
let subscriptions = self
|
let subscriptions = rpc
|
||||||
.subscriptions
|
.subscriptions
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|sub| rpc_proto::rpc::SubOpts {
|
.map(|sub| rpc_proto::rpc::SubOpts {
|
||||||
@ -270,9 +270,9 @@ impl Into<rpc_proto::Rpc> for GossipsubRpc {
|
|||||||
prune: Vec::new(),
|
prune: Vec::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let empty_control_msg = self.control_msgs.is_empty();
|
let empty_control_msg = rpc.control_msgs.is_empty();
|
||||||
|
|
||||||
for action in self.control_msgs {
|
for action in rpc.control_msgs {
|
||||||
match action {
|
match action {
|
||||||
// collect all ihave messages
|
// collect all ihave messages
|
||||||
GossipsubControlAction::IHave {
|
GossipsubControlAction::IHave {
|
||||||
|
@ -71,10 +71,10 @@ impl From<proto::message::ConnectionType> for KadConnectionType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<proto::message::ConnectionType> for KadConnectionType {
|
impl From<KadConnectionType> for proto::message::ConnectionType {
|
||||||
fn into(self) -> proto::message::ConnectionType {
|
fn from(val: KadConnectionType) -> Self {
|
||||||
use proto::message::ConnectionType::*;
|
use proto::message::ConnectionType::*;
|
||||||
match self {
|
match val {
|
||||||
KadConnectionType::NotConnected => NotConnected,
|
KadConnectionType::NotConnected => NotConnected,
|
||||||
KadConnectionType::Connected => Connected,
|
KadConnectionType::Connected => Connected,
|
||||||
KadConnectionType::CanConnect => CanConnect,
|
KadConnectionType::CanConnect => CanConnect,
|
||||||
@ -123,13 +123,13 @@ impl TryFrom<proto::message::Peer> for KadPeer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<proto::message::Peer> for KadPeer {
|
impl From<KadPeer> for proto::message::Peer {
|
||||||
fn into(self) -> proto::message::Peer {
|
fn from(peer: KadPeer) -> Self {
|
||||||
proto::message::Peer {
|
proto::message::Peer {
|
||||||
id: self.node_id.to_bytes(),
|
id: peer.node_id.to_bytes(),
|
||||||
addrs: self.multiaddrs.into_iter().map(|a| a.to_vec()).collect(),
|
addrs: peer.multiaddrs.into_iter().map(|a| a.to_vec()).collect(),
|
||||||
connection: {
|
connection: {
|
||||||
let ct: proto::message::ConnectionType = self.connection_ty.into();
|
let ct: proto::message::ConnectionType = peer.connection_ty.into();
|
||||||
ct as i32
|
ct as i32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user