fix: make compatible with edition2018 (#1522)

This commit is contained in:
Matthias Seitz 2022-07-27 23:36:21 +02:00 committed by GitHub
parent 3d76ce816a
commit 61821cc665
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -3,9 +3,10 @@
use crate::types::{BlockNumber, U256}; use crate::types::{BlockNumber, U256};
use ethabi::ethereum_types::FromDecStrErr; use ethabi::ethereum_types::FromDecStrErr;
use serde::{Deserialize, Deserializer}; use serde::{Deserialize, Deserializer};
use std::convert::TryFrom;
/// Helper type to parse both `u64` and `U256` /// Helper type to parse both `u64` and `U256`
#[derive(Deserialize)] #[derive(Copy, Clone, Deserialize)]
#[serde(untagged)] #[serde(untagged)]
pub enum Numeric { pub enum Numeric {
U256(U256), U256(U256),
@ -85,7 +86,7 @@ where
D: Deserializer<'de>, D: Deserializer<'de>,
{ {
let num = match NumericSeq::deserialize(deserializer)? { let num = match NumericSeq::deserialize(deserializer)? {
NumericSeq::Seq(seq) => seq.into_iter().next().unwrap().into(), NumericSeq::Seq(seq) => seq[0].into(),
NumericSeq::U256(n) => n, NumericSeq::U256(n) => n,
NumericSeq::Num(n) => U256::from(n), NumericSeq::Num(n) => U256::from(n),
}; };
@ -94,7 +95,7 @@ where
} }
/// Various block number representations, See [`lenient_block_number()`] /// Various block number representations, See [`lenient_block_number()`]
#[derive(Deserialize)] #[derive(Clone, Copy, Deserialize)]
#[serde(untagged)] #[serde(untagged)]
pub enum LenientBlockNumber { pub enum LenientBlockNumber {
BlockNumber(BlockNumber), BlockNumber(BlockNumber),
@ -141,7 +142,6 @@ pub fn lenient_block_number_seq<'de, D>(deserializer: D) -> Result<BlockNumber,
where where
D: Deserializer<'de>, D: Deserializer<'de>,
{ {
let num = let num = <[LenientBlockNumber; 1]>::deserialize(deserializer)?[0].into();
<[LenientBlockNumber; 1]>::deserialize(deserializer)?.into_iter().next().unwrap().into();
Ok(num) Ok(num)
} }

View File

@ -9,7 +9,11 @@ use core::convert::TryFrom;
use ethabi::encode; use ethabi::encode;
use proc_macro2::TokenStream; use proc_macro2::TokenStream;
use serde::{Deserialize, Deserializer, Serialize}; use serde::{Deserialize, Deserializer, Serialize};
use std::collections::{BTreeMap, HashSet}; use std::{
collections::{BTreeMap, HashSet},
convert::TryInto,
iter::FromIterator,
};
use syn::{ use syn::{
parse::Error, spanned::Spanned as _, AttrStyle, Data, DeriveInput, Expr, Fields, parse::Error, spanned::Spanned as _, AttrStyle, Data, DeriveInput, Expr, Fields,
GenericArgument, Lit, NestedMeta, PathArguments, Type, GenericArgument, Lit, NestedMeta, PathArguments, Type,