git.delta.rocks / unique-network / refs/commits / 4c1a924fb18b

difftreelog

refactor CanBePlacedInVec

Trubnikov Sergey2022-11-02parent: #527498b.patch.diff
in: master

2 files changed

modifiedcrates/evm-coder/procedural/src/solidity_interface.rsdiffbeforeafterboth
21// https://doc.rust-lang.org/reference/procedural-macros.html21// https://doc.rust-lang.org/reference/procedural-macros.html
2222
23use proc_macro2::TokenStream;23use proc_macro2::TokenStream;
24use quote::{quote, ToTokens, format_ident};24use quote::{quote, format_ident};
25use inflector::cases;25use inflector::cases;
26use std::fmt::Write;
27use syn::{26use syn::{
28 Expr, FnArg, GenericArgument, Generics, Ident, ImplItem, ImplItemMethod, ItemImpl, Lit, Meta,27 Expr, FnArg, GenericArgument, Generics, Ident, ImplItem, ImplItemMethod, ItemImpl, Lit, Meta,
29 MetaNameValue, PatType, PathArguments, ReturnType, Type,28 MetaNameValue, PatType, PathArguments, ReturnType, Type,
33};32};
3433
35use crate::{34use crate::{
36 fn_selector_str, parse_ident_from_pat, parse_ident_from_path, parse_path, parse_path_segment,35 parse_ident_from_pat, parse_ident_from_path, parse_path, parse_path_segment, parse_result_ok,
37 parse_result_ok, pascal_ident_to_call, pascal_ident_to_snake_call, snake_ident_to_pascal,36 pascal_ident_to_call, pascal_ident_to_snake_call, snake_ident_to_pascal,
38 snake_ident_to_screaming,37 snake_ident_to_screaming,
39};38};
modifiedcrates/evm-coder/src/abi.rsdiffbeforeafterboth
352352
353macro_rules! impl_abi_readable {353macro_rules! impl_abi_readable {
354 ($ty:ty, $method:ident, $dynamic:literal) => {354 ($ty:ty, $method:ident, $dynamic:literal) => {
355 impl sealed::CanBePlacedInVec for $ty {}
356
355 impl TypeHelper for $ty {357 impl TypeHelper for $ty {
356 fn is_dynamic() -> bool {358 fn is_dynamic() -> bool {
370}373}
371374
372impl_abi_readable!(bool, bool, false);375impl_abi_readable!(bool, bool, false);
373impl_abi_readable!(uint8, uint8, false);
374impl_abi_readable!(uint32, uint32, false);376impl_abi_readable!(uint32, uint32, false);
375impl_abi_readable!(uint64, uint64, false);377impl_abi_readable!(uint64, uint64, false);
376impl_abi_readable!(uint128, uint128, false);378impl_abi_readable!(uint128, uint128, false);
379impl_abi_readable!(address, address, false);381impl_abi_readable!(address, address, false);
380impl_abi_readable!(string, string, true);382impl_abi_readable!(string, string, true);
383
384impl TypeHelper for uint8 {
385 fn is_dynamic() -> bool {
386 false
387 }
388 fn size() -> usize {
389 ABI_ALIGNMENT
390 }
391}
392impl AbiRead for uint8 {
393 fn abi_read(reader: &mut AbiReader) -> Result<uint8> {
394 reader.uint8()
395 }
396}
381397
382impl TypeHelper for bytes {398impl TypeHelper for bytes {
383 fn is_dynamic() -> bool {399 fn is_dynamic() -> bool {
398 pub trait CanBePlacedInVec {}414 pub trait CanBePlacedInVec {}
399}415}
400
401impl sealed::CanBePlacedInVec for U256 {}
402impl sealed::CanBePlacedInVec for string {}
403impl sealed::CanBePlacedInVec for H160 {}
404impl sealed::CanBePlacedInVec for EthCrossAccount {}
405416
406impl<R: AbiRead + sealed::CanBePlacedInVec> AbiRead for Vec<R> {417impl<R: AbiRead + sealed::CanBePlacedInVec> AbiRead for Vec<R> {
407 fn abi_read(reader: &mut AbiReader) -> Result<Vec<R>> {418 fn abi_read(reader: &mut AbiReader) -> Result<Vec<R>> {
420 make_signature!(new nameof(R) fixed("[]"));431 make_signature!(new nameof(R) fixed("[]"));
421}432}
433
434impl sealed::CanBePlacedInVec for EthCrossAccount {}
422435
423impl TypeHelper for EthCrossAccount {436impl TypeHelper for EthCrossAccount {
424 fn is_dynamic() -> bool {437 fn is_dynamic() -> bool {