diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-09-08 12:11:55 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-09-08 12:11:55 +0200 |
| commit | 0ac09aef84b40fe4d1efc9580f49215ea8c94b2a (patch) | |
| tree | fcf457a60b33ac47a3223ab5f6bc865d8452cb75 /src/test/codegen/src-hash-algorithm | |
| parent | 50362372d68eae9b02a351f0fab42962cd0518de (diff) | |
| parent | 58ba1f51efab249411a932880e3c10d36355b166 (diff) | |
| download | rust-0ac09aef84b40fe4d1efc9580f49215ea8c94b2a.tar.gz rust-0ac09aef84b40fe4d1efc9580f49215ea8c94b2a.zip | |
Rollup merge of #62205 - timvermeulen:iter_order_by, r=KodrAus
Add Iterator comparison methods that take a comparison function
This PR adds `Iterator::{cmp_by, partial_cmp_by, eq_by, ne_by, lt_by, le_by, gt_by, ge_by}`. We already have `Iterator::{cmp, partial_cmp, ...}` which are less general (but not any simpler) than the ones I'm proposing here.
I'm submitting this PR now because #61505 has been merged, so this change should not have a noticeable effect on the `Iterator` docs page size.
The diff is quite messy, here's what I changed:
- The logic of `cmp` / `partial_cmp` / `eq` is moved to `cmp_by` / `partial_cmp_by` / `eq_by` respectively, changing `x.cmp(&y)` to `cmp(&x, &y)` in the `cmp` method where `cmp` is the given comparison function (and similar for `partial_cmp_by` and `eq_by`).
- `ne_by` / `lt_by` / `le_by` / `gt_by` / `ge_by` are each implemented in terms of one of the three methods above.
- The existing comparison methods are each forwarded to their `_by` counterpart, passing one of `Ord::cmp` / `PartialOrd::partial_cmp` / `PartialEq::eq` as the comparison function.
The corresponding `_by_key` methods aren't included because they're not as fundamental as the `_by` methods and can easily be implemented in terms of them. Is that reasonable, or would adding the `_by_key` methods be desirable for the sake of completeness?
I didn't add any tests – I couldn't think of any that weren't already covered by our existing tests. Let me know if there's a particular test that would be useful to add.
Diffstat (limited to 'src/test/codegen/src-hash-algorithm')
0 files changed, 0 insertions, 0 deletions
