Add Iterator comparison methods that take a comparison function by timvermeulen · Pull Request #62205 · rust-lang/rust (original) (raw)
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
rustbot added S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
and removed S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
labels
rustbot added S-inactive
Status: Inactive and waiting on the author. This is often applied to closed PRs.
and removed S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
labels
KodrAus added S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
and removed S-inactive
Status: Inactive and waiting on the author. This is often applied to closed PRs.
labels
bors added S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
and removed S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
labels
Centril added a commit to Centril/rust that referenced this pull request
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 rust-lang#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 tocmp_by
/partial_cmp_by
/eq_by
respectively, changingx.cmp(&y)
tocmp(&x, &y)
in thecmp
method wherecmp
is the given comparison function (and similar forpartial_cmp_by
andeq_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 ofOrd::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.
bors added a commit that referenced this pull request
Rollup of 4 pull requests
Successful merges:
- #62205 (Add Iterator comparison methods that take a comparison function)
- #64152 (Use backtrace formatting from the backtrace crate)
- #64265 (resolve: Mark more erroneous imports as used)
- #64267 (rustdoc: fix diagnostic with mixed code block styles)
Failed merges:
r? @ghost
Centril added a commit to Centril/rust that referenced this pull request
Document the unstable iter_order_by library feature
Tracking issue: rust-lang#64295
Follow-up for: rust-lang#62205
References the tracking issue and adds a page to the unstable book for the new unstable iter_order_by
feature.
Centril added a commit to Centril/rust that referenced this pull request
Document the unstable iter_order_by library feature
Tracking issue: rust-lang#64295
Follow-up for: rust-lang#62205
References the tracking issue and adds a page to the unstable book for the new unstable iter_order_by
feature.
Centril added a commit to Centril/rust that referenced this pull request
Document the unstable iter_order_by library feature
Tracking issue: rust-lang#64295
Follow-up for: rust-lang#62205
References the tracking issue and adds a page to the unstable book for the new unstable iter_order_by
feature.