HiveBrain v1.2.0
Get Started
← Back to all entries
snippetrustCritical

How to sort a vector in Rust?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
rusthowvectorsort

Problem

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

Solution

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

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

Context

Stack Overflow Q#26836488, score: 159

Revisions (0)

No revisions yet.