Skip to content

Entry APIs should have or_default for V: Default #44324

Closed
@jonhoo

Description

@jonhoo

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.

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

    Issue actions