I'd like to create a macro that checks the value of a provided bool and returns a string based on that value. I tried this:
macro_rules! dbg_bool{
() => {};
($val:expr $(,)?) => {
match $val {
//if $val is true return a green string
$($val == true) => {
"it was true".green()
}
//if $val is false return a red string
$($val == false) =>{
"it was false".red()
}
}
};
($($val:expr),+ $(,)?) => {
($(dbg_bool!($val)),+,)
};
}
but this gives me the error:
error: expected one of: `*`, `+`, or `?`
--> src/macros.rs:28:32
|
28 | $($val == true) => {
| ________________________________^
29 | | "it was true".green()
30 | | }
| |_____________^
What's the proper way to use equality operators to compare the $var
in my macro?