Implement matches! macro (#1777)

Fix #1775
This commit is contained in:
Herman Junge 2020-10-15 21:42:43 +00:00
parent 97be2ca295
commit d7b9d0dd9f
8 changed files with 19 additions and 62 deletions

View File

@ -519,10 +519,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
let mut out_list = enr.multiaddr();
out_list.retain(|addr| {
addr.iter()
.find(|v| match v {
MProtocol::Udp(_) => true,
_ => false,
})
.find(|v| matches!(v, MProtocol::Udp(_)))
.is_none()
});

View File

@ -228,18 +228,12 @@ impl Default for PeerConnectionStatus {
impl PeerConnectionStatus {
/// Checks if the status is connected.
pub fn is_connected(&self) -> bool {
match self {
PeerConnectionStatus::Connected { .. } => true,
_ => false,
}
matches!(self, PeerConnectionStatus::Connected { .. })
}
/// Checks if the status is connected.
pub fn is_dialing(&self) -> bool {
match self {
PeerConnectionStatus::Dialing { .. } => true,
_ => false,
}
matches!(self, PeerConnectionStatus::Dialing { .. })
}
/// The peer is either connected or in the process of being dialed.
@ -249,18 +243,12 @@ impl PeerConnectionStatus {
/// Checks if the status is banned.
pub fn is_banned(&self) -> bool {
match self {
PeerConnectionStatus::Banned { .. } => true,
_ => false,
}
matches!(self, PeerConnectionStatus::Banned { .. })
}
/// Checks if the status is disconnected.
pub fn is_disconnected(&self) -> bool {
match self {
Disconnected { .. } => true,
_ => false,
}
matches!(self, Disconnected { .. })
}
/// Modifies the status to Connected and increases the number of ingoing

View File

@ -29,26 +29,17 @@ pub struct SyncInfo {
impl PeerSyncStatus {
/// Returns true if the peer has advanced knowledge of the chain.
pub fn is_advanced(&self) -> bool {
match self {
PeerSyncStatus::Advanced { .. } => true,
_ => false,
}
matches!(self, PeerSyncStatus::Advanced { .. })
}
/// Returns true if the peer is up to date with the current chain.
pub fn is_synced(&self) -> bool {
match self {
PeerSyncStatus::Synced { .. } => true,
_ => false,
}
matches!(self, PeerSyncStatus::Synced { .. })
}
/// Returns true if the peer is behind the current chain.
pub fn is_behind(&self) -> bool {
match self {
PeerSyncStatus::Behind { .. } => true,
_ => false,
}
matches!(self, PeerSyncStatus::Behind { .. })
}
/// Updates the sync state given a fully synced peer.

View File

@ -136,20 +136,16 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
/// Returns if the peer is already connected.
pub fn is_connected(&self, peer_id: &PeerId) -> bool {
if let Some(PeerConnectionStatus::Connected { .. }) = self.connection_status(peer_id) {
true
} else {
false
}
matches!(
self.connection_status(peer_id),
Some(PeerConnectionStatus::Connected { .. })
)
}
/// If we are connected or currently dialing the peer returns true.
pub fn is_connected_or_dialing(&self, peer_id: &PeerId) -> bool {
match self.connection_status(peer_id) {
Some(PeerConnectionStatus::Connected { .. })
| Some(PeerConnectionStatus::Dialing { .. }) => true,
_ => false,
}
matches!(self.connection_status(peer_id), Some(PeerConnectionStatus::Connected { .. })
| Some(PeerConnectionStatus::Dialing { .. }))
}
/// Returns true if the peer is synced at least to our current head.
pub fn is_synced(&self, peer_id: &PeerId) -> bool {

View File

@ -277,10 +277,7 @@ impl<T: EthSpec> RPCCodedResponse<T> {
/// Tells the codec whether to decode as an RPCResponse or an error.
pub fn is_response(response_code: u8) -> bool {
match response_code {
0 => true,
_ => false,
}
matches!(response_code, 0)
}
/// Builds an RPCCodedResponse from a response code and an ErrorMessage
@ -311,10 +308,7 @@ impl<T: EthSpec> RPCCodedResponse<T> {
/// Returns true if this response always terminates the stream.
pub fn close_after(&self) -> bool {
match self {
RPCCodedResponse::Success(_) => false,
_ => true,
}
!matches!(self, RPCCodedResponse::Success(_))
}
}

View File

@ -47,10 +47,7 @@ impl SyncState {
/// Returns true if the node is synced.
pub fn is_synced(&self) -> bool {
match self {
SyncState::Synced => true,
_ => false,
}
matches!(self, SyncState::Synced)
}
}

View File

@ -156,10 +156,7 @@ impl MerkleTree {
/// Is this Merkle tree a leaf?
pub fn is_leaf(&self) -> bool {
match self {
MerkleTree::Leaf(_) => true,
_ => false,
}
matches!(self, MerkleTree::Leaf(_))
}
/// Return the leaf at `index` and a Merkle proof of its inclusion.

View File

@ -37,9 +37,6 @@ impl Error {
}
pub fn is_skipped(&self) -> bool {
match self {
Error::SkippedBls | Error::SkippedKnownFailure => true,
_ => false,
}
matches!(self, Error::SkippedBls | Error::SkippedKnownFailure)
}
}