Macro_rules! parsing w/ module path

I previously have:

    {
            $api_name:ident $struct_name:ident
    } 

which is great when I want to be able to match vs Foo Bar. However, I now want to be able to match vs some::path::Foo Bar.

I try:

    {
            $($path:ident)::* $api_name:ident $struct_name:ident
    } 

and I get an local ambiguity error of:

multiple parsing options: built-in NTs ident ('path') or ident ('api_name').

What is the idiomatic solution to this ?

Either put some kind of separator between path and api_name, or rewrite as a tt muncher.

2 Likes

maybe you just need the path capture instead of repetition of ident:

https://doc.rust-lang.org/reference/macros-by-example.html#metavariables

2 Likes

Combining @nerditation and @DanielKeep 's suggestions gives:

    {
            $api_name:path ; $struct_name:ident
    } 

which appears to have solved the issue

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.