I am trying to sort a vector of Substance structs:
#[derive(Debug, PartialOrd, PartialEq)]
struct Substance {
price: i32,
mass_kg: i32,
price_per_kg: f64,
}
by price_per_kg my current sorting code is:
// `substances` is a `vec` of `Substance`'s
substances.sort_unstable_by_key(|price_per_kg| price_per_kg);
This fails as the method requires the Ord trait. However, as f64 doesn't implement Eq I can't derive Ord and therefore I seemingly can't use this method.
Could you please let me know how I can do this sorting? Thanks,