From 61821cc6654a6f0c27f1294f660d5c0c1112b3fb Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 27 Jul 2022 23:36:21 +0200 Subject: [PATCH] fix: make compatible with edition2018 (#1522) --- ethers-core/src/types/serde_helpers.rs | 10 +++++----- ethers-core/src/types/transaction/eip712.rs | 6 +++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ethers-core/src/types/serde_helpers.rs b/ethers-core/src/types/serde_helpers.rs index 6939c01f..bd83a573 100644 --- a/ethers-core/src/types/serde_helpers.rs +++ b/ethers-core/src/types/serde_helpers.rs @@ -3,9 +3,10 @@ use crate::types::{BlockNumber, U256}; use ethabi::ethereum_types::FromDecStrErr; use serde::{Deserialize, Deserializer}; +use std::convert::TryFrom; /// Helper type to parse both `u64` and `U256` -#[derive(Deserialize)] +#[derive(Copy, Clone, Deserialize)] #[serde(untagged)] pub enum Numeric { U256(U256), @@ -85,7 +86,7 @@ where D: Deserializer<'de>, { 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::Num(n) => U256::from(n), }; @@ -94,7 +95,7 @@ where } /// Various block number representations, See [`lenient_block_number()`] -#[derive(Deserialize)] +#[derive(Clone, Copy, Deserialize)] #[serde(untagged)] pub enum LenientBlockNumber { BlockNumber(BlockNumber), @@ -141,7 +142,6 @@ pub fn lenient_block_number_seq<'de, D>(deserializer: D) -> Result, { - let num = - <[LenientBlockNumber; 1]>::deserialize(deserializer)?.into_iter().next().unwrap().into(); + let num = <[LenientBlockNumber; 1]>::deserialize(deserializer)?[0].into(); Ok(num) } diff --git a/ethers-core/src/types/transaction/eip712.rs b/ethers-core/src/types/transaction/eip712.rs index fb9100a3..868dccde 100644 --- a/ethers-core/src/types/transaction/eip712.rs +++ b/ethers-core/src/types/transaction/eip712.rs @@ -9,7 +9,11 @@ use core::convert::TryFrom; use ethabi::encode; use proc_macro2::TokenStream; use serde::{Deserialize, Deserializer, Serialize}; -use std::collections::{BTreeMap, HashSet}; +use std::{ + collections::{BTreeMap, HashSet}, + convert::TryInto, + iter::FromIterator, +}; use syn::{ parse::Error, spanned::Spanned as _, AttrStyle, Data, DeriveInput, Expr, Fields, GenericArgument, Lit, NestedMeta, PathArguments, Type,