title: What must I cast an `u8` to in able to use it as an index in my vector?
body: <p>I have a 2D vector in Rust which I am trying to index with a dynamic <code>u8</code> variable. An example of what I'm trying to do is below:</p>
  
  <pre><code>fn main() {
      let mut vec2d: Vec&lt;Vec&lt;u8&gt;&gt; = Vec::new();
  
      let row: u8 = 1;
      let col: u8 = 2;
  
      for i in 0..4 {
          let mut rowVec: Vec&lt;u8&gt; = Vec::new();
          for j in 0..4 {
              rowVec.push(j as u8);
          }
          vec2d.push(rowVec);
      }
  
      println!("{}", vec2d[row][col]);
  }
  </code></pre>
  
  <p>However, I get the error </p>
  
  <pre class="lang-none prettyprint-override"><code>error: the trait `core::ops::Index&lt;u8&gt;` is not implemented for the type `collections::vec::Vec&lt;collections::vec::Vec&lt;u8&gt;&gt;` [E0277]
  </code></pre>
  
  <p>In later versions of Rust, I get</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0277]: the trait bound `u8: std::slice::SliceIndex&lt;[std::vec::Vec&lt;u8&gt;]&gt;` is not satisfied
    --&gt; src/main.rs:15:20
     |
  15 |     println!("{}", vec2d[row][col]);
     |                    ^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
     |
     = help: the trait `std::slice::SliceIndex&lt;[std::vec::Vec&lt;u8&gt;]&gt;` is not implemented for `u8`
     = note: required because of the requirements on the impl of `std::ops::Index&lt;u8&gt;` for `std::vec::Vec&lt;std::vec::Vec&lt;u8&gt;&gt;`
  </code></pre>
  
  <p>What must I cast the <code>u8</code> to in able to use it as an index in my vector?</p>