macro_rules! call_on_self {
($F:ident) => {
self.$F()
}
}
struct F;
impl F {
fn dummy(&self) {}
fn test(&self) {
call_on_self!(dummy);
}
}
上述方法无效(Playground):
error[E0424]: expected value, found module `self`
--> src/lib.rs:3:9
|
3 | self.$F()
| ^^^^ `self` value is a keyword only available in methods with `self` parameter
...
11 | call_on_self!(dummy);
| --------------------- in this macro invocation
我不明白这为什么不起作用:宏是在self
可用的方法中调用的!这有可能吗?我是否应该将self
传递到宏中,因为否则宏无法解析self
?
我每晚都在使用rustc 1.19.0.