title: How to idiomatically convert between u32 and usize?
body: <p>This code works and prints "b":</p>
  
  <pre><code>fn main() {
      let s = "abc";
      let ch = s.chars().nth(1).unwrap();
      println!("{}", ch);
  }
  </code></pre>
  
  <p>On the other hand, this code results in a mismatch type error.</p>
  
  <pre><code>fn main() {
      let s = "abc";
      let n: u32 = 1;
      let ch = s.chars().nth(n).unwrap();
      println!("{}", ch);
  }
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code>error[E0308]: mismatched types
   --&gt; src/main.rs:5:28
    |
  5 |     let ch = s.chars().nth(n).unwrap();
    |                            ^ expected usize, found u32
  </code></pre>
  
  <p>For some external reason, I have to use the <code>u32</code> type for variable <code>n</code>. How can I convert <code>u32</code> to <code>usize</code> and use it in <code>nth()</code>?</p>