Can items in arrays be named for reference like in c++?

Hello, I have many values I want to put in an array. Instead of referencing them by number , Id like to give each one a name like in c++, where the compiler takes care of it. Is this possible in Rust?

Well you can:

  1. Define an enum. If the enum has no fields, then you can cast it to an integer.
  2. Define a bunch of constants and use the constants as index.
  3. Instead of an array, define a struct with named fields of the same type.

I´ll look into that. Thank you very much for your fast reply.

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.