It looks like for identifiers I can either use an existing token of ident kind, or create a fixed / literal identifier. But how to create a "derived" identifier? Meaning, having an existing token $id, I want to create some derived identifier like $id_suffix - exact name doesn't matter, really - as long as it's a new one, and deterministically derived from $id.
Asked
Active
Viewed 1,353 times
0
-
@Boiethios That question is itself a duplicate. – Sebastian Redl Dec 14 '18 at 08:30
-
@SebastianRedl I know, but I'm not satisfied with the answer you linked: `concat_idents` is a nightly feature that is not intended to be stabilized. The answer should begin with: "No, because that's unhygienic". – Boiethios Dec 14 '18 at 08:31
-
1How do you want to use that derived identifier? If you want to use it outside the macro, then it is impossible by design). If you want to use it inside the macro, then you probably don't need to derive it from the existing token, because the macro system ensures that there will be no collisions. Can you show us some code for how you would use a hypothetical `derive!` operation? – Jmb Dec 14 '18 at 08:51
-
The first two duplicates show a workaround by using the mashup crate. – Shepmaster Dec 14 '18 at 13:58
1 Answers
1
You can't. It's a limitation of the macro system.
There's a special macro that lets you create an identifier, but you can't use it in useful locations like the name of a new variable.

Sebastian Redl
- 69,373
- 8
- 123
- 157
-
-
The first two duplicates show a workaround by using the mashup crate. – Shepmaster Dec 14 '18 at 13:59
-
Actually, I figured out a possible solution - at least, for my use case. I can create an inner module, named after an identifier, passed into the macro - $id:ident - and then put any number of "derived" types in it. Already tested it, seems to be working. – rincewind Dec 14 '18 at 20:48