title: How to sort a Vector in descending order in Rust?
body: <p>In Rust, the sorting methods of a <code>Vec</code> always arrange the elements from smallest to largest. What is a general-purpose way of sorting from largest to smallest instead? </p>
  
  <p>If you have a vector of numbers, you can provide a key extraction function that "inverts" the number like this:</p>
  
  <pre><code>let mut numbers: Vec&lt;u32&gt; = vec![100_000, 3, 6, 2];
  numbers.sort_by_key(|n| std::u32::MAX - n);
  </code></pre>
  
  <p>But that's not very clear, and it's not straightforward to extend that method to other types like strings.</p>