Could anyone help explaining why the following would fail with error:
error: no rules expected the token
.
--> src/main.rs:12:9
|
1 | macro_rules! foo {
| ---------------- when calling this macro
...
12 | foo!(baz.a);
| ^ no rules expected this token in macro call
macro_rules! foo {
($bar:ident) => {{
}};
}
struct Baz {
a: f64
}
fn main() {
let baz = Baz{a:1.0};
foo!(baz.a);
}
The code work if the main function is changed to:
fn main() {
let baz = Baz{a:1.0};
let a = baz.a;
foo!(a);
}
Is there a way to directly pass struct field as macro argument? E.g., write baz.a
in foo!(baz.a)
.