-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
BinaryHeap: implement IterMut #98522
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @m-ou-se (or someone else) soon. Please see the contribution instructions for more information. |
link tracking issue
This seems like quite a specialized method and type, and not at all like the other To me, it doesn't seem like the kind of common operation that warrants its own method and type, since the same can be achieved with |
@m-ou-se Thanks for taking a look. It's true you can modify through
in lieu of This seems sub-optimal because
As far as the drop behavior, I think it's fairly unsurprising, especially since we already have |
I don't think that pattern is common enough to warrant a new method and type just to be able to write those three lines as one.
It's surpsing behaviour for something we call
How common is that? In which use cases does that happen, and what is the alternative? If you want to add a new API to the standard library, you'll have to show that the problem it solves is big enough to be worth it. If something is uncommon and there is already a safe and reasonable alternative, it usually does not meet the bar for addition to the standard library. |
Yeah I think you're right. Thanks again for taking the time (also for all the hard work on std::sync). |
In that case, I'm closing this PR. (But please don't let that discourage you from future contributions!) (Note that next time you want to propose a new API for the standard library, feel free open an issue on the libs-team repository to get feedback on the public interface before implementing it, to potentially save yourself some work.) |
I recently had a need for this and decided to go ahead and implement it.
Some notes:
iter_mut()
is implemented forBinaryHeap<T: Ord>
. Generalizing toBinaryHeap<T>
would require a specialized drop. This limitation might be fine (not sure why you would use a heap without ordering anyway) but it feels a little odd.btree
module (DormantMutRef
). It might make sense to move that file.IterMut
can be made double-ended. However it would greatly complicate things, and since the iteration order is mostly arbitrary, I don't see much point.