title: How do I find the index of an element in an array, vector or slice?
body: <p>I need to find an index of an element in a vector of strings. This is what I got so far:</p>
  
  <pre><code>fn main() {
      let test: Vec&lt;String&gt; = vec![
          "one".to_string(),
          "two".to_string(),
          "three".to_string(),
          "four".to_string(),
      ];
  
      let index: i32 = test
          .iter()
          .enumerate()
          .find(|&amp;r| r.1.to_string() == "two".to_string())
          .unwrap()
          .0;
  }
  </code></pre>
  
  <p>It produces an error:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0308]: mismatched types
    --&gt; src/main.rs:9:22
     |
  9  |       let index: i32 = test
     |  ______________________^
  10 | |         .iter()
  11 | |         .enumerate()
  12 | |         .find(|&amp;r| r.1.to_string() == "two".to_string())
  13 | |         .unwrap()
  14 | |         .0;
     | |__________^ expected i32, found usize
  </code></pre>
  
  <p>I assume that's because <code>enumerate()</code> returns a tuple of <code>(usize, _)</code> (correct me if I'm wrong), but how do I convert <code>usize</code> to <code>i32</code> here? If there is a better approach, I'm open to suggestions.</p>