Skip to content

Entry APIs should have or_default for V: Default #44324

Closed
@jonhoo

Description

@jonhoo
Contributor

The various Entry APIs (e.g., hash_map::Entry, btree_map::Entry) currently have or_insert, and or_insert_with. However, when V: Default, I believe they should also have an or_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 to or_insert_with(Default::default), I would argue that or_default is much more readable.

I'd be happy to take a stab at implementing this, but wanted to air the idea first.

Activity

added
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
on Sep 4, 2017
steveklabnik

steveklabnik commented on Sep 5, 2017

@steveklabnik
Member

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!

jonhoo

jonhoo commented on Sep 5, 2017

@jonhoo
ContributorAuthor

@steveklabnik PR submitted!

added
B-unstableBlocker: Implemented in the nightly compiler and unstable.
on Sep 11, 2017
added a commit that references this issue on Sep 12, 2017

Auto merge of #44344 - jonhoo:entry_or_default, r=BurntSushi

removed
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
on Nov 15, 2017
dtolnay

dtolnay commented on Nov 15, 2017

@dtolnay
Member

An unstable or_default() method was added in #44344. This issue is now the tracking issue for stabilization.

added
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
on Jan 22, 2018
khuey

khuey commented on Feb 20, 2018

@khuey
Contributor

Is there any reason not to just stabilize this?

SimonSapin

SimonSapin commented on Mar 17, 2018

@SimonSapin
Contributor

In Nightly for 6 months, looks good to me to stabilize.

@rfcbot fcp merge

rfcbot

rfcbot commented on Mar 17, 2018

@rfcbot
Collaborator

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.

added
proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
on Mar 17, 2018
rfcbot

rfcbot commented on Mar 19, 2018

@rfcbot
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

removed
proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
on Mar 19, 2018
rfcbot

rfcbot commented on Mar 29, 2018

@rfcbot
Collaborator

The final comment period is now complete.

added
disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.
and removed
final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
on May 24, 2018
added a commit that references this issue on Jun 10, 2018

Auto merge of #51079 - GuillaumeGomez:stabilize-entry-or-default, r=S…

900037e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-collectionsArea: `std::collections`B-unstableBlocker: Implemented in the nightly compiler and unstable.C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @steveklabnik@jonhoo@SimonSapin@khuey@BurntSushi

        Issue actions

          Entry APIs should have or_default for V: Default · Issue #44324 · rust-lang/rust