If there an easier way to sort a Vec<(f32, f32)>
by sorting by the first element of the tuple, and fall back to the second if they are equals than this?
let mut my_vec: Vec<(f32, f32)> = /* ... */;
my_vec.sort_by(|&a, &b| {
let cmp = a.0.partial_cmp(&b.0).unwrap();
if cmp != Ordering::Equal {
return cmp;
}
a.1.partial_cmp(&b.1).unwrap()
});
All the values I have in my vec are "normal numbers" (no +/-infinity, NaN, …), so I'm totally fine with unwrap of equivalent.
Note: sort()
doesn't works since f32
doesn't implement Ord
.