Remove some macros (#12742)

# Description
Replaces some macros with regular functions or other code.
This commit is contained in:
Ian Manske
2024-05-03 08:35:37 +00:00
committed by GitHub
parent eff2f1b3b0
commit f32ecc641f
5 changed files with 220 additions and 302 deletions

View File

@ -36,6 +36,15 @@ impl Argument {
Argument::Spread(e) => e.span,
}
}
pub fn expr(&self) -> Option<&Expression> {
match self {
Argument::Named((_, _, expr)) => expr.as_ref(),
Argument::Positional(expr) | Argument::Unknown(expr) | Argument::Spread(expr) => {
Some(expr)
}
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]

View File

@ -72,24 +72,29 @@ fn get_filesize_format(
) -> Option<byte_unit::Unit> {
// filesize_metric always overrides the unit of filesize_format.
let metric = filesize_metric.unwrap_or(!format_value.ends_with("ib"));
macro_rules! either {
($metric:ident, $binary:ident) => {
Some(if metric {
byte_unit::Unit::$metric
} else {
byte_unit::Unit::$binary
})
};
}
match format_value {
"b" => Some(byte_unit::Unit::B),
"kb" | "kib" => either!(KB, KiB),
"mb" | "mib" => either!(MB, MiB),
"gb" | "gib" => either!(GB, GiB),
"tb" | "tib" => either!(TB, TiB),
"pb" | "pib" => either!(TB, TiB),
"eb" | "eib" => either!(EB, EiB),
_ => None,
if metric {
match format_value {
"b" => Some(byte_unit::Unit::B),
"kb" | "kib" => Some(byte_unit::Unit::KB),
"mb" | "mib" => Some(byte_unit::Unit::MB),
"gb" | "gib" => Some(byte_unit::Unit::GB),
"tb" | "tib" => Some(byte_unit::Unit::TB),
"pb" | "pib" => Some(byte_unit::Unit::TB),
"eb" | "eib" => Some(byte_unit::Unit::EB),
_ => None,
}
} else {
match format_value {
"b" => Some(byte_unit::Unit::B),
"kb" | "kib" => Some(byte_unit::Unit::KiB),
"mb" | "mib" => Some(byte_unit::Unit::MiB),
"gb" | "gib" => Some(byte_unit::Unit::GiB),
"tb" | "tib" => Some(byte_unit::Unit::TiB),
"pb" | "pib" => Some(byte_unit::Unit::TiB),
"eb" | "eib" => Some(byte_unit::Unit::EiB),
_ => None,
}
}
}