How to sort a vector in Rust?

Maxim Sloyko picture Maxim Sloyko · Nov 10, 2014 · Viewed 33.7k times · Source

What is the currently recommended method for sorting values in a vector?

Answer

Chris Morgan picture Chris Morgan · Nov 10, 2014

A mutable slice of elements with a total ordering has a sort method.

Because Vec<T> implements DerefMut<[T]>, you can call this method directly on a vector, so vector.sort() works.