-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Entry APIs should have or_default for V: Default #44324
Comments
Generally, the way the libs team works is "open a PR if a change is small, open an RFC if a change is big." I'm not on the libs team, but this feels pretty small to me; you already almost have an implementation in the comment! |
@steveklabnik PR submitted! |
Add or_default to Entry APIs As argued for in #44324, this PR adds a new `or_default` method to the various `Entry` APIs (currently just for `BTreeMap` and `HashMap`) when `V: Default`. This method is effectively a shorthand for `or_insert_with(Default::default)`.
An unstable |
Is there any reason not to just stabilize this? |
In Nightly for 6 months, looks good to me to stabilize. @rfcbot fcp merge |
Team member @SimonSapin has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period is now complete. |
…imonSapin Stabilize entry-or-default Fixes #44324. cc @SimonSapin
The various Entry APIs (e.g.,
hash_map::Entry
,btree_map::Entry
) currently haveor_insert
, andor_insert_with
. However, whenV: Default
, I believe they should also have anor_default
. This would make it nicer to work with things like maps of maps, maps of lists, etc. While it's true that this is equivalent toor_insert_with(Default::default)
, I would argue thator_default
is much more readable.I'd be happy to take a stab at implementing this, but wanted to air the idea first.
The text was updated successfully, but these errors were encountered: