title: Is there a way to index an array by enums in Rust?
body: <p>I want to represent a table of data in the memory like the following:</p>
  
  <pre class="lang-none prettyprint-override"><code>     | USD | EUR |
  -----+-----+-----+
  John | 100 | 50  |
  -----+-----+-----+
  Tom  | 300 | 200 |
  -----+-----+-----+
  Nick | 200 | 0   |
  -----+-----+-----+
  </code></pre>
  
  <p>There is a known set of people, each of them owns some currency.</p>
  
  <p>And I have the following enums:</p>
  
  <pre><code>enum Person {
      John,
      Tom,
      Nick
  }
  
  enum Currency {
      USD,
      EUR
  }
  </code></pre>
  
  <p>I'd like to encode this data as 2D array, and it would be cool to be able to index array elements not by <code>usize</code> but by <code>enum</code>. E.g.:</p>
  
  <pre><code>data[Person::John][Currency::USD] = 100;
  </code></pre>
  
  <p>Is it possible to do with arrays and enums in Rust? Or is there any other data structure that would serve for this?</p>
  
  <p>I am aware of <code>HashMap</code>, but it's not exactly what I want because: </p>
  
  <ul>
  <li><p><code>HashMap</code> works on the heap (what makes it much slower than regular stack allocated array) </p></li>
  <li><p><code>HashMap</code> gives me no guarantee that item exist. E.g. every time I want to get something I have to unwrap it and handle <code>None</code> case, what is not very handy in comparison with usage of normal array.</p></li>
  </ul>
  
  <p>This is different from <a href="https://stackoverflow.com/questions/28028854/how-do-i-match-enum-values-with-an-integer">How do I match enum values with an integer?</a> because I am not interested in converting enum to <code>usize</code>; I just want a handy way to access array/map items by enum.</p>