鉴于:
format!("{red}{}{reset}", "text", red = "RED", blue = "BLUE", reset = "RESET");
编译器退出时出错:
error: named argument never used
--> example.rs:1:47
|
1 | format!("{red}{}{reset}", "text", red = "RED", blue = "BLUE", reset = "RESET");
| ^^^^^^^^^^^^^
通常,这不应该是一个问题,因为blue
应该删除,但我的usecase是一个包装宏(简化):
macro_rules! log { ($fmt:expr, $($arg:tt)*) => { println!($fmt, $($arg)*, blue = "BLUE", red = "RED", reset = "RESET"); }; }
有时,它被这样使用(简化),但有时候使用不同的颜色,你得到了要点:
log!("{red}{}{reset}", "text");
编译器退出时出现类似错误:
error: named argument never used
--> example.rs:3:26
|
3 | println!($fmt, $($arg)*, blue = "BLUE", red = "RED", reset = "RESET");
| ^^^^^^^^^^^^^
是否可以忽略未使用的参数,而不是对它们进行错误?