On Sunday, 20 February 2022 at 11:08:55 UTC, partypooper wrote:
Hello, I'm new to D.

Title is self described, is it possible to use keyword as struct field?

Maybe it is XYproblem, so here I will describe a little what I need. I'm parsing some json currently with [mir-ion](https://code.dlang.org/packages/mir-ion) (better/simpler suggestions for only json de/serialization?), that has "version" as one of it's keys, so I can't use that as field in my struct. Maybe some annotation in mir library to parse "version" into other struct field name, can't find though (its docs pretty concise).

Unfortunately I'm not able to help you with mir-ion. But I see two questions here:

keyword as struct field

I believe this is the case for the most languages - keyword is not allowed as a variable name.

usage of `version` keyword as a variable name

IMO having `version` keyword in D is unexpected language design. No one will complain about keywords that are widely used in the industry (like `struct`, `int` etc). But `version`?! I hit this problem multiple times already and the only solution for me was to use `version_` instead.

Reply via email to