Macro_rules! creates a newline while generating generic parameter list

I am trying to generate something using macro_rules!:

macro_rules! justlist {
    ($($element:expr),*) => {{
        struct JustList< $( Member_$element, )* > { }
    }};
}

justlist!(member, tember, amber);

This generates the following output:

struct JustList<Member_ member,Member_ tember,Member_ amber, >{}

I was expecting to see Member_amber, but got Member_ amber (notice the space).

This is unexpected because in the original source I have put in no space - Member_$element,. So I assume, it's not coming from me.

Question - how can I make the macro emit without a space?

UPDATE: ohhh, concat! and stringify!... okay...

That works for making static string slices, but that won't work in your macro, because you can't have string slices as generic parameter names of a struct. paste would be my recommendation for concatenating identifiers.

1 Like

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.