Simplify enum -> str with strum (#2164)

## Issue Addressed

NA

## Proposed Changes

As per #2100, uses derives from the sturm library to implement AsRef<str> and AsStaticRef to easily get str values from enums without creating new Strings. Furthermore unifies all attestation error counter into one IntCounterVec vector.

These works are originally by @blacktemplar, I've just created this PR so I can resolve some merge conflicts.

## Additional Info

NA


Co-authored-by: blacktemplar <blacktemplar@a1.net>
This commit is contained in:
Paul Hauner
2021-01-19 06:33:58 +00:00
parent 8892114f52
commit 805e152f66
14 changed files with 82 additions and 255 deletions

View File

@@ -11,6 +11,7 @@ use serde::{
use std::collections::HashSet;
use std::net::{IpAddr, SocketAddr};
use std::time::Instant;
use strum::AsRefStr;
use types::{EthSpec, SubnetId};
use PeerConnectionStatus::*;
@@ -320,21 +321,13 @@ impl Default for PeerStatus {
}
/// Connection Direction of connection.
#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, AsRefStr)]
#[strum(serialize_all = "snake_case")]
pub enum ConnectionDirection {
Incoming,
Outgoing,
}
impl ConnectionDirection {
pub fn as_static_str(&self) -> &'static str {
match self {
ConnectionDirection::Incoming => "incoming",
ConnectionDirection::Outgoing => "outgoing",
}
}
}
/// Connection Status of the peer.
#[derive(Debug, Clone)]
pub enum PeerConnectionStatus {