Skip to content

Commit

Permalink
Simplify code following Andrew's suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
cmichi committed Nov 19, 2024
1 parent b5ce8a1 commit 4cb1d5a
Showing 1 changed file with 9 additions and 49 deletions.
58 changes: 9 additions & 49 deletions crates/cargo-contract/src/cmd/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>()
.join(", ");
Expand Down Expand Up @@ -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)
)
}};
}

0 comments on commit 4cb1d5a

Please sign in to comment.