## 事象
以下のようなコードを書く。
```rust
let xs = vec![1.0, 50.0, 15.0, 25.0, 30.0];
let sorted = xs.iter().sorted().collect_vec();
```
以下のエラーが出る。
```
the trait bound `{float}: std::cmp::Ord` is not satisfied [E0277] the trait `std::cmp::Ord` is not implemented for `{float}`
```
## 原因
f32やf64には[[Ordトレイト]]が実装されていないから。
## 解決方法
[[rust-ordered-float]]を使う。
どうしてもf64やf32を使いたい場合は`partial_cmp`を使う。[[PartialOrdトレイト]]は実装されているため。
```rust
let sorted = xs
.into_iter()
.sorted_by(|a, b| a.partial_cmp(b).unwrap())
.collect_vec();
```
## 参考
- [【Rust】Vec<f32>やVec<f64>に対してソートを実行する \- yiskw note](https://yiskw713.hatenablog.com/entry/2021/06/09/075419)