I am trying to match a struct
in a Rust macro. I need to pull the
struct
apart somewhat to get its name. I figured that the block
matcher would do the trick. Consider, for example this:
macro_rules! multi {
(struct $name:ident $block:block) => {
enum George {$name}
}
}
multi!{
struct Fred {
a:String
}
}
which expands to
enum George { Fred, }
which is about right.
However, if I turn this back into a struct
, it fails.
macro_rules! multi {
(struct $name:ident $block:block) => {
struct $name $block
}
}
which gives this error.
error: expected `where`, `{`, `(`, or `;` after struct name, found `{ a: String }`
--> src/main.rs:64:22
|
64 | struct $name $block
| ^^^^^^ expected `where`, `{`, `(`, or `;` after struct name
It looks like {a: String}
is being treated as a single token, rather
than being re-parsed; but it is what should be going in there.