mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 18:41:05 +00:00
Clean up sc-network (#9761)
* Clean up sc-network - Avoid using clone() for the Copy type `PeerId`. - Use `find_map` for `filter_map` and `next`. - Use `Self`. * More on Copy types * Cargo +nightly fmt --all * More .. * fmt * Revert vec![default_notif_handshake_message]
This commit is contained in:
@@ -169,9 +169,9 @@ impl Role {
|
||||
impl fmt::Display for Role {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Role::Full => write!(f, "FULL"),
|
||||
Role::Light => write!(f, "LIGHT"),
|
||||
Role::Authority { .. } => write!(f, "AUTHORITY"),
|
||||
Self::Full => write!(f, "FULL"),
|
||||
Self::Light => write!(f, "LIGHT"),
|
||||
Self::Authority { .. } => write!(f, "AUTHORITY"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -242,7 +242,7 @@ pub struct ProtocolId(smallvec::SmallVec<[u8; 6]>);
|
||||
|
||||
impl<'a> From<&'a str> for ProtocolId {
|
||||
fn from(bytes: &'a str) -> ProtocolId {
|
||||
ProtocolId(bytes.as_bytes().into())
|
||||
Self(bytes.as_bytes().into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ pub struct MultiaddrWithPeerId {
|
||||
impl MultiaddrWithPeerId {
|
||||
/// Concatenates the multiaddress and peer ID into one multiaddress containing both.
|
||||
pub fn concat(&self) -> Multiaddr {
|
||||
let proto = multiaddr::Protocol::P2p(From::from(self.peer_id.clone()));
|
||||
let proto = multiaddr::Protocol::P2p(From::from(self.peer_id));
|
||||
self.multiaddr.clone().with(proto)
|
||||
}
|
||||
}
|
||||
@@ -360,9 +360,9 @@ pub enum ParseErr {
|
||||
impl fmt::Display for ParseErr {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
ParseErr::MultiaddrParse(err) => write!(f, "{}", err),
|
||||
ParseErr::InvalidPeerId => write!(f, "Peer id at the end of the address is invalid"),
|
||||
ParseErr::PeerIdMissing => write!(f, "Peer id is missing from the address"),
|
||||
Self::MultiaddrParse(err) => write!(f, "{}", err),
|
||||
Self::InvalidPeerId => write!(f, "Peer id at the end of the address is invalid"),
|
||||
Self::PeerIdMissing => write!(f, "Peer id is missing from the address"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -370,16 +370,16 @@ impl fmt::Display for ParseErr {
|
||||
impl std::error::Error for ParseErr {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
ParseErr::MultiaddrParse(err) => Some(err),
|
||||
ParseErr::InvalidPeerId => None,
|
||||
ParseErr::PeerIdMissing => None,
|
||||
Self::MultiaddrParse(err) => Some(err),
|
||||
Self::InvalidPeerId => None,
|
||||
Self::PeerIdMissing => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<multiaddr::Error> for ParseErr {
|
||||
fn from(err: multiaddr::Error) -> ParseErr {
|
||||
ParseErr::MultiaddrParse(err)
|
||||
Self::MultiaddrParse(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -401,7 +401,7 @@ pub enum SyncMode {
|
||||
|
||||
impl Default for SyncMode {
|
||||
fn default() -> Self {
|
||||
SyncMode::Full
|
||||
Self::Full
|
||||
}
|
||||
}
|
||||
|
||||
@@ -479,7 +479,7 @@ impl NetworkConfiguration {
|
||||
node_key: NodeKeyConfig,
|
||||
net_config_path: Option<PathBuf>,
|
||||
) -> Self {
|
||||
NetworkConfiguration {
|
||||
Self {
|
||||
net_config_path,
|
||||
listen_addresses: Vec::new(),
|
||||
public_addresses: Vec::new(),
|
||||
@@ -548,7 +548,7 @@ pub struct SetConfig {
|
||||
|
||||
impl Default for SetConfig {
|
||||
fn default() -> Self {
|
||||
SetConfig {
|
||||
Self {
|
||||
in_peers: 25,
|
||||
out_peers: 75,
|
||||
reserved_nodes: Vec::new(),
|
||||
@@ -585,7 +585,7 @@ pub struct NonDefaultSetConfig {
|
||||
impl NonDefaultSetConfig {
|
||||
/// Creates a new [`NonDefaultSetConfig`]. Zero slots and accepts only reserved nodes.
|
||||
pub fn new(notifications_protocol: Cow<'static, str>, max_notification_size: u64) -> Self {
|
||||
NonDefaultSetConfig {
|
||||
Self {
|
||||
notifications_protocol,
|
||||
max_notification_size,
|
||||
fallback_names: Vec::new(),
|
||||
@@ -644,8 +644,8 @@ impl NonReservedPeerMode {
|
||||
/// Attempt to parse the peer mode from a string.
|
||||
pub fn parse(s: &str) -> Option<Self> {
|
||||
match s {
|
||||
"accept" => Some(NonReservedPeerMode::Accept),
|
||||
"deny" => Some(NonReservedPeerMode::Deny),
|
||||
"accept" => Some(Self::Accept),
|
||||
"deny" => Some(Self::Deny),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -662,7 +662,7 @@ pub enum NodeKeyConfig {
|
||||
|
||||
impl Default for NodeKeyConfig {
|
||||
fn default() -> NodeKeyConfig {
|
||||
NodeKeyConfig::Ed25519(Secret::New)
|
||||
Self::Ed25519(Secret::New)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -687,9 +687,9 @@ pub enum Secret<K> {
|
||||
impl<K> fmt::Debug for Secret<K> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Secret::Input(_) => f.debug_tuple("Secret::Input").finish(),
|
||||
Secret::File(path) => f.debug_tuple("Secret::File").field(path).finish(),
|
||||
Secret::New => f.debug_tuple("Secret::New").finish(),
|
||||
Self::Input(_) => f.debug_tuple("Secret::Input").finish(),
|
||||
Self::File(path) => f.debug_tuple("Secret::File").field(path).finish(),
|
||||
Self::New => f.debug_tuple("Secret::New").finish(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user