Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
remove EthAbiType derive generated unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
zsluedem committed Jan 15, 2023
1 parent 10b18e0 commit 69c410a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions ethers-contract/ethers-contract-derive/src/abi_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ pub fn derive_tokenizeable_impl(input: &DeriveInput) -> proc_macro2::TokenStream

let assignments = fields.named.iter().map(|f| {
let name = f.ident.as_ref().expect("Named fields have names");
quote_spanned! { f.span() => #name: #core_crate::abi::Tokenizable::from_token(iter.next().unwrap())? }
let name_str = name.to_string();
quote_spanned! { f.span() => #name: iter
.next()
.ok_or_else(|| #core_crate::abi::InvalidOutputType(::std::format!(
"Struct field {:} doesn't have correspond token.", #name_str
)))
.and_then(|t| #core_crate::abi::Tokenizable::from_token(t))?
}
});
let init_struct_impl = quote! { Self { #(#assignments,)* } };

Expand All @@ -59,7 +66,13 @@ pub fn derive_tokenizeable_impl(input: &DeriveInput) -> proc_macro2::TokenStream
let tokenize_predicates = quote! { #(#tokenize_predicates,)* };

let assignments = fields.unnamed.iter().map(|f| {
quote_spanned! { f.span() => #core_crate::abi::Tokenizable::from_token(iter.next().unwrap())? }
quote_spanned! { f.span() => iter
.next()
.ok_or_else(|| #core_crate::abi::InvalidOutputType(::std::format!(
"Struct unnamed field doesn't have correspond token."
)))
.and_then(|t| #core_crate::abi::Tokenizable::from_token(t))?
}
});
let init_struct_impl = quote! { Self(#(#assignments,)* ) };

Expand Down

0 comments on commit 69c410a

Please sign in to comment.