title: Why is capitalizing the first letter of a string so convoluted in Rust?
body: <p>I'd like to capitalize the first letter of a <code>&amp;str</code>. It's a simple problem and I hope for a simple solution. Intuition tells me to do something like this:</p>
  
  <pre><code>let mut s = "foobar";
  s[0] = s[0].to_uppercase();
  </code></pre>
  
  <p>But <code>&amp;str</code>s can't be indexed like this. The only way I've been able to do it seems overly convoluted. I convert the <code>&amp;str</code> to an iterator, convert the iterator to a vector, upper case the first item in the vector, which creates an iterator, which I index into, creating an <code>Option</code>, which I unwrap to give me the upper-cased first letter. Then I convert the vector into an iterator, which I convert into a <code>String</code>, which I convert to a <code>&amp;str</code>.</p>
  
  <pre><code>let s1 = "foobar";
  let mut v: Vec&lt;char&gt; = s1.chars().collect();
  v[0] = v[0].to_uppercase().nth(0).unwrap();
  let s2: String = v.into_iter().collect();
  let s3 = &amp;s2;
  </code></pre>
  
  <p>Is there an easier way than this, and if so, what? If not, why is Rust designed this way?</p>
  
  <p><a href="https://stackoverflow.com/questions/38342805/how-do-i-collect-from-multiple-iterator-types#">Similar question</a></p>