title: Why I can not use u8 as an index value of a Rust array?
body: <p>I am new to Rust, and I am trying to write simple bitwise replacer.</p>
  
  <p>I have this code:</p>
  
  <pre><code>const TABLE: [u64; 8] = [
      0xC462A5B9E8D703F1,
      0x68239A5C1E47BD0F,
      0xB3582FADE174C960,
      0xC821D4F670A53E9B,
      0x7F5A816D093EB42C,
      0x5DF692CAB78143E0,
      0x8E25691CF4B0DA37,
      0x17ED05834FA69CB2,
  ];
  
  fn get_part(u: u64, i: u8) -&gt; u8 {
      ((u &amp; (0xFu64 &lt;&lt; (16 - i))) &gt;&gt; (16 - i)) as u8
  }
  
  fn process(o: u8, i1: u8, i2: u8) -&gt; u8 {
      let left: u8 = o &gt;&gt; 4;
      let right: u8 = o &amp; 0xF;
      (get_part(TABLE[left], left) &lt;&lt; 4) + get_part(TABLE[right], right)
  }
  </code></pre>
  
  <p>I got errors like this one:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0277]: the trait bound `u8: std::slice::SliceIndex&lt;[u64]&gt;` is not satisfied
    --&gt; src/main.rs:19:15
     |
  19 |     (get_part(TABLE[left], left) &lt;&lt; 4) + get_part(TABLE[right], right)
     |               ^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
     |
     = help: the trait `std::slice::SliceIndex&lt;[u64]&gt;` is not implemented for `u8`
     = note: required because of the requirements on the impl of `std::ops::Index&lt;u8&gt;` for `[u64]`
  
  error[E0277]: the trait bound `u8: std::slice::SliceIndex&lt;[u64]&gt;` is not satisfied
    --&gt; src/main.rs:19:51
     |
  19 |     (get_part(TABLE[left], left) &lt;&lt; 4) + get_part(TABLE[right], right)
     |                                                   ^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
     |
     = help: the trait `std::slice::SliceIndex&lt;[u64]&gt;` is not implemented for `u8`
     = note: required because of the requirements on the impl of `std::ops::Index&lt;u8&gt;` for `[u64]`
  </code></pre>
  
  <p>I don't understand why it's illegal to use <code>u8</code> as the index value. How can I convert <code>u8</code> to a compatible type? I don't even know which type is compatible.</p>