Skip to content

Tracking Issue for Option::get_or_insert_default #82901

Closed
@camsteffen

Description

@camsteffen

Feature gate: #![feature(option_get_or_insert_default)]

This is a tracking issue for adding Option::get_or_insert_default.

Basically, it is a shorthand for option.get_or_insert_with(Default::default). It differs with unwrap_or_default since it does not consume the Option. This is useful, for example, when you have an Option as a struct field or inside a data structure like Vec<Option<T>>.

Public API

impl<T> Option<T> {
    pub fn get_or_insert_default(&mut self) -> &mut T where T: Default;
}

Steps / History

Unresolved Questions

  • None yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-result-optionArea: Result and Option combinatorsC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-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