chore: add enum helper functions (#5865)

This commit is contained in:
Matthias Seitz
2023-12-27 20:49:03 +01:00
committed by GitHub
parent ed774e9a81
commit 22a450822e

View File

@ -151,7 +151,7 @@ use jsonrpsee::{
Methods, RpcModule,
};
use serde::{Deserialize, Serialize, Serializer};
use strum::{AsRefStr, EnumVariantNames, ParseError, VariantNames};
use strum::{AsRefStr, EnumIter, EnumVariantNames, IntoStaticStr, ParseError, VariantNames};
use tower::layer::util::{Identity, Stack};
use tower_http::cors::CorsLayer;
use tracing::{instrument, trace};
@ -739,7 +739,19 @@ impl fmt::Display for RpcModuleSelection {
}
/// Represents RPC modules that are supported by reth
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, AsRefStr, EnumVariantNames, Deserialize)]
#[derive(
Debug,
Clone,
Copy,
Eq,
PartialEq,
Hash,
AsRefStr,
IntoStaticStr,
EnumVariantNames,
EnumIter,
Deserialize,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "kebab-case")]
pub enum RethRpcModule {
@ -777,6 +789,18 @@ impl RethRpcModule {
pub const fn all_variants() -> &'static [&'static str] {
Self::VARIANTS
}
/// Returns all variants of the enum
pub fn modules() -> impl IntoIterator<Item = RethRpcModule> {
use strum::IntoEnumIterator;
Self::iter()
}
/// Returns the string representation of the module.
#[inline]
pub fn as_str(&self) -> &'static str {
self.into()
}
}
impl FromStr for RethRpcModule {