From 4cb1d5a5e239a7fd6c3d791456552da85cf9dbe6 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Tue, 19 Nov 2024 15:23:51 +0100 Subject: [PATCH] Simplify code following Andrew's suggestion --- crates/cargo-contract/src/cmd/config.rs | 58 ++++--------------------- 1 file changed, 9 insertions(+), 49 deletions(-) diff --git a/crates/cargo-contract/src/cmd/config.rs b/crates/cargo-contract/src/cmd/config.rs index 1405a44c5..6c8bc1d4a 100644 --- a/crates/cargo-contract/src/cmd/config.rs +++ b/crates/cargo-contract/src/cmd/config.rs @@ -212,13 +212,13 @@ where #[macro_export] macro_rules! call_with_config_internal { - ($obj:tt ,$function:tt, $config_name:expr, $($config:ty),*) => { + ($obj:tt ,$function:tt, $config_name:expr, $( ($config_str:literal, $config_obj:ty) ),*) => { match $config_name { $( - stringify!($config) => $obj.$function::<$config>().await, + $config_str => $obj.$function::<$config_obj>().await, )* _ => { - let configs = vec![$(stringify!($config)),*].iter() + let configs = vec![$($config_str),*].iter() .map(|s| s.to_string()) .collect::>() .join(", "); @@ -253,54 +253,14 @@ macro_rules! call_with_config { $config_name ); - let res_nonspaced = $crate::call_with_config_internal!( + $crate::call_with_config_internal!( $obj, $function, - format!("$crate::cmd::config::{}", $config_name).as_str(), + $config_name, // All available chain configs need to be specified here - $crate::cmd::config::Polkadot, - $crate::cmd::config::Substrate, - $crate::cmd::config::Ecdsachain - ); - if !res_nonspaced.is_err() { - return res_nonspaced - } - - let res_spaced = $crate::call_with_config_internal!( - $obj, - $function, - format!("$crate :: cmd :: config :: {}", $config_name).as_str(), - // All available chain configs need to be specified here - $crate::cmd::config::Polkadot, - $crate::cmd::config::Substrate, - $crate::cmd::config::Ecdsachain - ); - if !res_spaced.is_err() { - return res_spaced - } - - let res_spaced_without_dollar = $crate::call_with_config_internal!( - $obj, - $function, - format!("crate :: cmd :: config :: {}", $config_name).as_str(), - // All available chain configs need to be specified here - $crate::cmd::config::Polkadot, - $crate::cmd::config::Substrate, - $crate::cmd::config::Ecdsachain - ); - if !res_spaced_without_dollar.is_err() { - return res_spaced_without_dollar - } - - let res_nonspaced_without_dollar = $crate::call_with_config_internal!( - $obj, - $function, - format!("crate::cmd::config::{}", $config_name).as_str(), - // All available chain configs need to be specified here - $crate::cmd::config::Polkadot, - $crate::cmd::config::Substrate, - $crate::cmd::config::Ecdsachain - ); - res_nonspaced_without_dollar + ("Polkadot", $crate::cmd::config::Polkadot), + ("Substrate", $crate::cmd::config::Substrate), + ("Ecdssachain", $crate::cmd::config::Ecdsachain) + ) }}; }