migrated ethjson to serde 1.0
This commit is contained in:
parent
286526072f
commit
9c911c7a28
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -685,9 +685,9 @@ dependencies = [
|
||||
"clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore-util 1.7.0",
|
||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -6,8 +6,8 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
[dependencies]
|
||||
ethcore-util = { path = "../util" }
|
||||
rustc-hex = "1.0"
|
||||
serde = "0.9"
|
||||
serde_json = "0.9"
|
||||
serde_derive = "0.9"
|
||||
serde = "1.0"
|
||||
serde_json = "1.0"
|
||||
serde_derive = "1.0"
|
||||
clippy = { version = "0.0.103", optional = true}
|
||||
|
||||
|
@ -67,16 +67,16 @@ impl FromStr for Bytes {
|
||||
}
|
||||
}
|
||||
|
||||
impl Deserialize for Bytes {
|
||||
impl<'a> Deserialize<'a> for Bytes {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer {
|
||||
deserializer.deserialize(BytesVisitor)
|
||||
where D: Deserializer<'a> {
|
||||
deserializer.deserialize_any(BytesVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
struct BytesVisitor;
|
||||
|
||||
impl Visitor for BytesVisitor {
|
||||
impl<'a> Visitor<'a> for BytesVisitor {
|
||||
type Value = Bytes;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
|
@ -42,13 +42,13 @@ macro_rules! impl_hash {
|
||||
}
|
||||
}
|
||||
|
||||
impl Deserialize for $name {
|
||||
impl<'a> Deserialize<'a> for $name {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer {
|
||||
where D: Deserializer<'a> {
|
||||
|
||||
struct HashVisitor;
|
||||
|
||||
impl Visitor for HashVisitor {
|
||||
impl<'b> Visitor<'b> for HashVisitor {
|
||||
type Value = $name;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -75,7 +75,7 @@ macro_rules! impl_hash {
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize(HashVisitor)
|
||||
deserializer.deserialize_any(HashVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,7 @@
|
||||
use std::fmt;
|
||||
use std::marker::PhantomData;
|
||||
use serde::{Deserialize, Deserializer};
|
||||
use serde::de::{Error, Visitor};
|
||||
use serde::de::value::ValueDeserializer;
|
||||
use serde::de::{Error, Visitor, IntoDeserializer};
|
||||
|
||||
/// Deserializer of empty string values into optionals.
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
@ -16,10 +15,10 @@ pub enum MaybeEmpty<T> {
|
||||
None,
|
||||
}
|
||||
|
||||
impl<T> Deserialize for MaybeEmpty<T> where T: Deserialize {
|
||||
impl<'a, T> Deserialize<'a> for MaybeEmpty<T> where T: Deserialize<'a> {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer {
|
||||
deserializer.deserialize(MaybeEmptyVisitor::new())
|
||||
where D: Deserializer<'a> {
|
||||
deserializer.deserialize_any(MaybeEmptyVisitor::new())
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +34,7 @@ impl<T> MaybeEmptyVisitor<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Visitor for MaybeEmptyVisitor<T> where T: Deserialize {
|
||||
impl<'a, T> Visitor<'a> for MaybeEmptyVisitor<T> where T: Deserialize<'a> {
|
||||
type Value = MaybeEmpty<T>;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
|
@ -236,6 +236,7 @@ mod tests {
|
||||
eip161d_transition: Some(Uint(U256::from(0x47))),
|
||||
ecip1010_pause_transition: None,
|
||||
ecip1010_continue_transition: None,
|
||||
ecip1017_era_rounds: None,
|
||||
max_code_size: None,
|
||||
max_gas_limit_transition: None,
|
||||
max_gas_limit: None,
|
||||
@ -282,6 +283,7 @@ mod tests {
|
||||
eip161d_transition: None,
|
||||
ecip1010_pause_transition: None,
|
||||
ecip1010_continue_transition: None,
|
||||
ecip1017_era_rounds: None,
|
||||
max_code_size: None,
|
||||
max_gas_limit_transition: None,
|
||||
max_gas_limit: None,
|
||||
|
@ -21,7 +21,7 @@ use std::collections::BTreeMap;
|
||||
use std::str::FromStr;
|
||||
use bytes::Bytes;
|
||||
use serde::{Deserialize, Deserializer};
|
||||
use serde::de::{Error as ErrorTrait, Visitor, MapVisitor, SeqVisitor};
|
||||
use serde::de::{Error as ErrorTrait, Visitor, MapAccess, SeqAccess};
|
||||
|
||||
/// Trie test input.
|
||||
#[derive(Debug, PartialEq)]
|
||||
@ -30,35 +30,35 @@ pub struct Input {
|
||||
pub data: BTreeMap<Bytes, Option<Bytes>>,
|
||||
}
|
||||
|
||||
impl Deserialize for Input {
|
||||
impl<'a> Deserialize<'a> for Input {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'a>
|
||||
{
|
||||
deserializer.deserialize(InputVisitor)
|
||||
deserializer.deserialize_any(InputVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
struct InputVisitor;
|
||||
|
||||
impl Visitor for InputVisitor {
|
||||
impl<'a> Visitor<'a> for InputVisitor {
|
||||
type Value = Input;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "a map of bytes into bytes")
|
||||
}
|
||||
|
||||
fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error> where V: MapVisitor {
|
||||
fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error> where V: MapAccess<'a> {
|
||||
let mut result = BTreeMap::new();
|
||||
|
||||
loop {
|
||||
let key_str: Option<String> = visitor.visit_key()?;
|
||||
let key_str: Option<String> = visitor.next_key()?;
|
||||
let key = match key_str {
|
||||
Some(ref k) if k.starts_with("0x") => Bytes::from_str(k).map_err(V::Error::custom)?,
|
||||
Some(k) => Bytes::new(k.into_bytes()),
|
||||
None => { break; }
|
||||
};
|
||||
|
||||
let val_str: Option<String> = visitor.visit_value()?;
|
||||
let val_str: Option<String> = visitor.next_value()?;
|
||||
let val = match val_str {
|
||||
Some(ref v) if v.starts_with("0x") => Some(Bytes::from_str(v).map_err(V::Error::custom)?),
|
||||
Some(v) => Some(Bytes::new(v.into_bytes())),
|
||||
@ -75,11 +75,11 @@ impl Visitor for InputVisitor {
|
||||
Ok(input)
|
||||
}
|
||||
|
||||
fn visit_seq<V>(self, mut visitor: V) -> Result<Self::Value, V::Error> where V: SeqVisitor {
|
||||
fn visit_seq<V>(self, mut visitor: V) -> Result<Self::Value, V::Error> where V: SeqAccess<'a> {
|
||||
let mut result = BTreeMap::new();
|
||||
|
||||
loop {
|
||||
let keyval: Option<Vec<Option<String>>> = visitor.visit()?;
|
||||
let keyval: Option<Vec<Option<String>>> = visitor.next_element()?;
|
||||
let keyval = match keyval {
|
||||
Some(k) => k,
|
||||
_ => { break; },
|
||||
|
@ -50,16 +50,16 @@ impl Into<u8> for Uint {
|
||||
}
|
||||
}
|
||||
|
||||
impl Deserialize for Uint {
|
||||
impl<'a> Deserialize<'a> for Uint {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer {
|
||||
deserializer.deserialize(UintVisitor)
|
||||
where D: Deserializer<'a> {
|
||||
deserializer.deserialize_any(UintVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
struct UintVisitor;
|
||||
|
||||
impl Visitor for UintVisitor {
|
||||
impl<'a> Visitor<'a> for UintVisitor {
|
||||
type Value = Uint;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
|
Loading…
Reference in New Issue
Block a user