Sort a Rust vector in place using the sort or sort_by_key methods on a mutable collection.
Use the sort or sort_by_key method on a mutable vector to reorder its elements in place.
let mut numbers = vec![3, 1, 4, 1, 5];
numbers.sort();
let mut rectangles = vec![
Rectangle { width: 10, height: 1 },
Rectangle { width: 3, height: 5 },
];
rectangles.sort_by_key(|r| r.width);
Sorting a vector rearranges the items inside it into a specific order, like numbers from smallest to largest. You must mark the vector as mutable so Rust knows you intend to change its contents. Think of it like organizing a messy stack of papers on your desk; once sorted, the papers stay in that new order.