Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Self not recognized in blocks macro parameters
Hi!
I'm currently trying to create a macro that involves having as a parameter the block of a function,
as in this example:
macro_rules! implement {
(
$name:ty,
fn $func:ident(&self) $block:block
) => {
impl $name {
fn $func(&self) $block
}
}
}
struct Foo {
bar: i32,
}
implement! {
Foo,
fn print_bar(&self) {
println!("bar: {}", self.bar);
}
}
even though cargo expand
's shows the correct expansion (which includes &self in the function signature), this code doesn't compile.. The compiler gives this error:
expected value, found module `self` [E0424]
`self` value is a keyword only available in methods with a `self` parameter
So, I wanted to ask:
macro
syntax)2 posts - 2 participants
🏷️ rust_feed