support field values in err! macro

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-08-01 08:41:47 +00:00
parent 5b1642f641
commit 5add9a8c34
4 changed files with 127 additions and 31 deletions

View file

@ -8,12 +8,12 @@ pub const EMPTY: &str = "";
/// arguments are provided the first is assumed to be a format string.
#[macro_export]
macro_rules! format_maybe {
($s:literal) => {
($s:literal $(,)?) => {
if $crate::is_format!($s) { std::format!($s).into() } else { $s.into() }
};
($($args:expr),*) => {
std::format!($($args),*).into()
($s:literal, $($args:tt)+) => {
std::format!($s, $($args)+).into()
};
}
@ -24,6 +24,10 @@ macro_rules! is_format {
($s:literal) => {
::const_str::contains!($s, "{") && ::const_str::contains!($s, "}")
};
($($s:tt)+) => {
false
};
}
#[inline]