chore(rpc): add convenience from impl (#1686)

This commit is contained in:
Matthias Seitz
2023-03-09 21:50:26 +01:00
committed by GitHub
parent ce633c22e5
commit 89305b883a

View File

@@ -1,10 +1,12 @@
use reth_primitives::U256;
use serde::{
de::{Error, Visitor},
Deserialize, Deserializer, Serialize, Serializer,
};
use std::fmt;
/// A hex encoded or decimal index
/// A hex encoded or decimal index that's intended to be used as a rust index, hence it's
/// deserialized into a `usize`.
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Default)]
pub struct Index(usize);
@@ -14,6 +16,12 @@ impl From<Index> for usize {
}
}
impl From<Index> for U256 {
fn from(idx: Index) -> Self {
U256::from(idx.0)
}
}
impl Serialize for Index {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where