Skip to content

introduce the Comparable trait for btree internals #144506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

conradludgate
Copy link
Contributor

Apologies if this is not the way to do things. I have a usecase for the Comparable trait that K: Borrow, Q: Ord does not satisfy. See my comment.

It was previously mentioned regarding the Equivalent trait to start an ACP if someone has a compelling use-case, although I don't have the energy to do that right now. However I thought I would at least introduce the trait as an implementation detail, just to get the ball rolling if anyone else does have more time/motivation than myself.

This does not introduce any changes to public API, nor should it have any impact to performance or behaviour. The one thing of note is that I've used a flipped version of the trait.

The one annoying thing is that we still need Q: Ord in order to provide the panic messages for bad usage. One could likely address this but it would move the branch inside the search loop which might impact performance. Another approach is to move the condition out, but that won't help if we want the same helpful panic condition in any potential exposed API. Note that this check is not needed for memory safety (as we already have to deal with invalid Ord impls) so maybe such a check is not really that necessary. The alternative is we accept this Q: Ord bound as not a significant limitation. I don't really know/care - this is not an ACP so there's not really any API to discuss :)

@rustbot
Copy link
Collaborator

rustbot commented Jul 26, 2025

r? @ibraheemdev

rustbot has assigned @ibraheemdev.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 26, 2025
@ibraheemdev
Copy link
Member

ibraheemdev commented Jul 28, 2025

r? libs-api because this is related to a future API change, I'm sure if this is the best way to proceed.

@rustbot rustbot added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jul 28, 2025
@rustbot rustbot assigned Amanieu and unassigned ibraheemdev Jul 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants