Not really. In my suggestion the macro does not define how it needs self
- in fact, it has not macro-level access to self
(the expression before the macro) at all! All it does is generate tokens based on the macro arguments and replace the macro invocation (and it alone - not the tokens that come before it. Though the .
does count as part of the macro invocation and gets replaces) with these tokens.
If I were to convert your example to my suggestion, it'd look like that (I'm using the style describe in this comment):
macro_rules! a(&self) {
.() => {
.match {
this => {
println!("{:?}", this.a);
println!("{:?}", this.b);
}
}
};
}
And then this:
do_something().a!();
Will resolve to:
do_something().match {
this => {
println!("{:?}", this.a);
println!("{:?}", this.b);
}
}
Which is equivalent to today's:
match do_something() {
this => {
println!("{:?}", this.a);
println!("{:?}", this.b);
}
}