Add Option::get_or_default by camsteffen · Pull Request #82849 · rust-lang/rust (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation8 Commits2 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

@camsteffen

Tracking issue: #82901

The original issue is #55042, which was closed, but for an invalid reason (see discussion there). Opening this to reconsider (I hope that's okay). It seems like the only gap for Option being "entry-like".

I ran into a need for this method where I had a Vec<Option<MyData>> and wanted to do vec[n].get_or_default().my_data_method(). Using an Option as an inner component of a data structure is probably where the need for this will normally arise.

@rust-highfive

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@Mark-Simulacrum

r? @joshtriplett for T-libs member review

I am not sure this pulls enough weight over the insert_with method, but it's also pretty common to have _default variants in std, so not really opposed.

@joshtriplett

This seems reasonable to me. The naming seems consistent with other methods in std.

However, this should not be added as insta-stable. This needs to be marked unstable (the feature-gate name seems fine), and it needs a tracking issue.

r=me if made unstable with a tracking issue.

@camsteffen

@rust-log-analyzer

This comment has been minimized.

@camsteffen

@camsteffen

@camsteffen

Added missing feature flag in the docs example.
Added a usage to the compiler.

@joshtriplett

@bors

📌 Commit 1cc8c4d has been approved by joshtriplett

@bors bors added S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Mar 8, 2021

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request

Mar 9, 2021

@Dylan-DPC

…=joshtriplett

Add Option::get_or_default

Tracking issue: rust-lang#82901

The original issue is rust-lang#55042, which was closed, but for an invalid reason (see discussion there). Opening this to reconsider (I hope that's okay). It seems like the only gap for Option being "entry-like".

I ran into a need for this method where I had a Vec<Option<MyData>> and wanted to do vec[n].get_or_default().my_data_method(). Using an Option as an inner component of a data structure is probably where the need for this will normally arise.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request

Mar 9, 2021

@Dylan-DPC

…=joshtriplett

Add Option::get_or_default

Tracking issue: rust-lang#82901

The original issue is rust-lang#55042, which was closed, but for an invalid reason (see discussion there). Opening this to reconsider (I hope that's okay). It seems like the only gap for Option being "entry-like".

I ran into a need for this method where I had a Vec<Option<MyData>> and wanted to do vec[n].get_or_default().my_data_method(). Using an Option as an inner component of a data structure is probably where the need for this will normally arise.

bors added a commit to rust-lang-ci/rust that referenced this pull request

Mar 10, 2021

@bors

Labels

S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.