title: How can I sort the characters of a string in Rust?
body: <p>I have the string "laxmi" and I need to sort it in descending alphabetical order, producing "xmlia". I have written this:</p>
  
  <pre><code>fn main() {
      let wordy: String = "I am a hello world example";
  
      let chars: Vec&lt;char&gt; = wordy.chars().vector();
      chars.sort_by(|a, b| b.cmp(a));
  
      // let s: String = chars.into_iter().collect();
      println!("test{:?}", chars);
      let s = String::from_iter(chars);
      println!("{}", s);
  }
  </code></pre>
  
  <p>This only works if <code>wordy</code> is a <code>&amp;str</code>, but I have a <code>String</code>. How can I convert the <code>String</code> to a vector of <code>char</code> so that I can sort the string?</p>